<?php

namespace App\Modules\HR\EmployeeSelfService\Requests;

use App\Modules\HR\PermissionRequests\Models\PermissionRequest;
use App\Modules\HR\PermissionRequests\Support\PermissionRequestType;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

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

    /**
     * @return array<string, mixed>
     */
    public function rules(): array
    {
        return [
            'type' => ['required', 'string', Rule::in(PermissionRequestType::all())],
            'request_date' => ['required', 'date'],
            'start_at' => ['nullable', 'date'],
            'end_at' => ['nullable', 'date', 'after_or_equal:start_at'],
            'reason' => ['nullable', 'string', 'max:5000'],
        ];
    }
}
