<?php

namespace App\Modules\HR\Attendance\Requests;

use App\Modules\HR\Attendance\Support\AttendanceCorrectionStatus;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

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

    /**
     * @return array<string, array<int, string|\Illuminate\Validation\Rules\In>>
     */
    public function rules(): array
    {
        return [
            'status' => [
                'nullable',
                'string',
                Rule::in([
                    '',
                    'all',
                    AttendanceCorrectionStatus::PENDING,
                    AttendanceCorrectionStatus::APPROVED,
                    AttendanceCorrectionStatus::REJECTED,
                ]),
            ],
        ];
    }

    public function statusFilter(): ?string
    {
        $s = (string) $this->input('status', AttendanceCorrectionStatus::PENDING);
        if ($s === '' || $s === 'all') {
            return null;
        }

        return $s;
    }
}
