<?php

namespace App\Http\Requests\Leave;

use Illuminate\Foundation\Http\FormRequest;

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

    public function rules(): array
    {
        return [
            'user_id' => 'nullable|integer|exists:users,id',
            'leave_type' => 'required|string|in:annual,half_am,half_pm,sick,family,maternity,parental',
            'start_date' => 'required|date|after_or_equal:today',
            'end_date' => 'required|date|after_or_equal:start_date',
            'days' => 'required|numeric|min:0.5|max:365',
            'reason' => 'nullable|string|max:1000',
        ];
    }

    public function messages(): array
    {
        return [
            'leave_type.required' => __('validation.required', ['attribute' => '휴가유형']),
            'leave_type.in' => __('validation.in', ['attribute' => '휴가유형']),
            'start_date.required' => __('validation.required', ['attribute' => '시작일']),
            'start_date.after_or_equal' => __('validation.after_or_equal', ['attribute' => '시작일', 'date' => '오늘']),
            'end_date.required' => __('validation.required', ['attribute' => '종료일']),
            'end_date.after_or_equal' => __('validation.after_or_equal', ['attribute' => '종료일', 'date' => '시작일']),
            'days.required' => __('validation.required', ['attribute' => '사용일수']),
            'days.min' => __('validation.min.numeric', ['attribute' => '사용일수', 'min' => 0.5]),
        ];
    }
}
