<?php

namespace Modules\Payroll\DTO;

class EmployeeLoansFilter
{
    public function __construct(
        public readonly ?string $search = null,
        public readonly ?string $status = null,
        public readonly ?string $from_date = null,
        public readonly ?string $to_date = null,
        public readonly ?int $employee_id = null,
        public readonly ?int $perPage = 15,
    ) {}

    public static function fromRequest($request): self
    {
        return new self(
            status: $request->filled('status') ? $request->status : null,
            search: $request->filled('search') ? trim($request->search) : null,
            from_date: $request->filled('from_date') ? $request->from_date : null,
            to_date: $request->filled('to_date') ? $request->to_date : null,
            employee_id: $request->filled('employee_id') ? (int) $request->employee_id : null,
            perPage: $request->input('per_page', 10),
        );
    }
}
