<?php

namespace App\Modules\HR\Overtime\Requests;

use App\Modules\HR\Overtime\Models\OvertimeRequest;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class StoreOvertimeRequestRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()?->can('create', OvertimeRequest::class) ?? false;
    }

    /**
     * @return array<string, mixed>
     */
    public function rules(): array
    {
        $tenantId = $this->user()?->tenant_id;

        return [
            'employee_id' => [
                'required',
                'integer',
                Rule::exists('employees', 'id')->where(fn ($q) => $q->where('tenant_id', $tenantId)),
            ],
            'attendance_date' => ['required', 'date'],
            'overtime_minutes' => ['required', 'integer', 'min:1', 'max:1440'],
            'reason' => ['nullable', 'string', 'max:5000'],
        ];
    }
}
