<?php

namespace Modules\Inventory\DTO;

use Illuminate\Http\Request;

class ProductUnitConversionFilter
{
    public function __construct(
        public readonly ?int $id,
        public readonly ?int $product_id,
        public readonly ?int $base_unit_id,
        public readonly ?int $unit_level_one,
        public readonly ?int $unit_level_two,
        public readonly ?int $unit_level_three,
        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,
            product_id: $request->filled('product_id') ? (int) $request->product_id : null,
            base_unit_id: $request->filled('base_unit_id') ? (int) $request->base_unit_id : null,
            unit_level_one: $request->filled('unit_level_one') ? (int) $request->unit_level_one : null,
            unit_level_two: $request->filled('unit_level_two') ? (int) $request->unit_level_two : null,
            unit_level_three: $request->filled('unit_level_three') ? (int) $request->unit_level_three : 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,
        );
    }
}
