<?php

namespace App\DTOs\Excul;

use App\Enums\IzinStatus;

final readonly class ListExculRequest
{
    public function __construct(
        public int          $perPage,
        public string       $search,
        public ?IzinStatus  $status,   // ← IzinStatus
        public string       $kel,
        public string       $tanggal,
        public int          $page,
    ) {}

    public static function fromRequest(\Illuminate\Http\Request $request): self
    {
        return new self(
            perPage: min((int) $request->query('per_page', 10), 100),
            search:  trim((string) $request->query('search', '')),
            status:  IzinStatus::fromString((string) $request->query('status', '')),
            kel:     trim((string) $request->query('kel', '')),
            tanggal: (string) $request->query('tanggal', ''),
            page:    max(1, (int) $request->query('page', 1)),
        );
    }

    public function cacheKey(): string
    {
        return 'excul:list:' . md5(serialize([
            $this->perPage,
            $this->search,
            $this->status?->value,
            $this->kel,
            $this->tanggal,
            $this->page,
        ]));
    }
}