<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class StoreStaffHistoryRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize(): bool
    {
        return auth()->user()->can('create staff history');
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\Rule|array|string>
     */
    public function rules(): array
    {
        return [
            'organization_id' => 'required|exists:organizations,id',
            'user_id' => 'nullable|exists:users,id',
            'staff_name' => 'required|string|max:191',
            'position' => 'required|string|max:191',
            'employment_start_date' => 'required|date',
            'employment_end_date' => 'nullable|date|after:employment_start_date',
            'employment_status' => 'required|in:current,former',
            'termination_reason' => 'nullable|string',
            'passport' => 'nullable|file|mimes:jpeg,jpg,png,pdf|max:5120',
        ];
    }

    /**
     * Get the error messages for the defined validation rules.
     *
     * @return array<string, string>
     */
    public function messages(): array
    {
        return [
            'organization_id.required' => 'Please select an organization.',
            'staff_name.required' => 'Staff name is required.',
            'position.required' => 'Position is required.',
            'employment_end_date.after' => 'Employment end date must be after start date.',
            'passport.mimes' => 'The passport file must be a JPEG, PNG, or PDF.',
            'passport.max' => 'The passport file must not exceed 5MB.',
        ];
    }
}
