<?php

namespace Modules\Inventory\DTO;

use Illuminate\Http\Request;

class ProductListFilter
{
    public function __construct(
        public readonly ?int $id,
        public readonly ?int $inventory_department_id,
        public readonly ?int $category_id,
        public readonly ?int $base_unit_id,
        public readonly string $status,
        public readonly ?string $search,
        public readonly ?int $perPage = 15,
    ) {}

    public static function fromRequest(Request $request): self
    {
        return new self(
            id: $request->filled('id') ? (int) $request->id : null,
            inventory_department_id: $request->filled('inventory_department_id') ? (int) $request->inventory_department_id : null,
            category_id: $request->filled('category_id') ? (int) $request->category_id : null,
            base_unit_id: $request->filled('base_unit_id') ? (int) $request->base_unit_id : null,
            status: $request->filled('status') ? $request->status : '',
            search: $request->filled('search') ? trim($request->search) : null,
            perPage: $request->filled('per_page') ? (int) $request->per_page : 15,
        );
    }
}
