<?php

namespace App\Modules\HR\EmployeeSelfService\Requests;

use Illuminate\Foundation\Http\FormRequest;

class MeAttendanceIndexRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true;
    }

    /**
     * @return array<string, array<int, string>>
     */
    public function rules(): array
    {
        return [
            'from' => ['nullable', 'date'],
            'to' => ['nullable', 'date', 'after_or_equal:from'],
            'employee_id' => ['nullable', 'integer'],
        ];
    }

    public function fromOrDefault(string $default): string
    {
        return (string) ($this->input('from') ?: $default);
    }

    public function toOrDefault(string $default): string
    {
        return (string) ($this->input('to') ?: $default);
    }
}
