<?php

namespace Modules\HR\DTO;

class HrSettingFilter
{
    public function __construct(
        public readonly ?string $search = null,
        public readonly ?string $status = null,
        public readonly ?string $salary_revision_status = null,
        public readonly ?string $holiday_group_ids = null,
        public readonly ?bool $is_default = null,
        public readonly ?string $from_date = null,
        public readonly ?string $to_date = null,
        public readonly ?int $perPage = 15,
    ) {}

    public static function fromRequest($request): self
    {
        return new self(
            status: $request->filled('status') ? $request->status : 'Active',
            search: $request->filled('search') ? trim($request->search) : null,
            salary_revision_status: $request->filled('salary_revision_status') ? trim($request->salary_revision_status) : null,
            holiday_group_ids: $request->input('holiday_group_ids'),
            is_default: $request->filled('is_default') ? filter_var($request->input('is_default'), FILTER_VALIDATE_BOOLEAN) : null,
            from_date: $request->input('from_date'),
            to_date: $request->input('to_date'),
            perPage: $request->input('per_page', 10),
        );
    }
}
