<?php

namespace App\Modules\HR\Offboarding\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class OffboardingRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()?->can($this->route('case') ? 'offboarding.update' : 'offboarding.create') ?? false;
    }

    public function rules(): array
    {
        return [
            'employee_id' => ['required', Rule::exists('employees', 'id')->where(fn ($q) => $q->where('tenant_id', $this->user()?->tenant_id))],
            'type' => ['required', Rule::in(['resignation', 'termination'])], 'reason' => ['required', 'string', 'max:5000'],
            'last_working_date' => ['required', 'date'], 'exit_interview_notes' => ['nullable', 'string'],
            'clearance_notes' => ['nullable', 'string'], 'knowledge_transfer_notes' => ['nullable', 'string'],
            'final_settlement_status' => ['sometimes', Rule::in(['pending', 'processing', 'paid', 'waived'])],
            'experience_letter_issued' => ['sometimes', 'boolean'],
        ];
    }
}
