<?php

namespace App\DTOs;

use Carbon\Carbon;
use Illuminate\Http\Request;

class UserFilterDto
{
    public function __construct(
        public readonly string $selectedMonth,
        public readonly ?string $search = null,
        public readonly ?string $status = '1',
        public readonly ?string $role = null,
        public readonly ?string $department = null,
        public readonly ?string $flagSend = null
    ) {}

    /**
     * Create a DTO instance from an HTTP Request.
     */
    public static function fromRequest(Request $request): self
    {
        return new self(
            selectedMonth: (string) $request->input('month', Carbon::now()->format('Y-m')),
            search: $request->input('search'),
            status: $request->has('status') ? (string) $request->input('status') : '1',
            role: $request->input('role'),
            department: $request->input('department'),
            flagSend: $request->input('flag_send')
        );
    }
}
