<?php

namespace App\Http\Requests\V1\Salary;

use Illuminate\Foundation\Http\FormRequest;

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

    public function rules(): array
    {
        return [
            'employee_id' => ['required', 'integer', 'exists:users,id'],
            'year' => ['required', 'integer', 'min:2020', 'max:2100'],
            'month' => ['required', 'integer', 'min:1', 'max:12'],
            'base_salary' => ['required', 'numeric', 'min:0'],
            'total_allowance' => ['nullable', 'numeric', 'min:0'],
            'total_overtime' => ['nullable', 'numeric', 'min:0'],
            'total_bonus' => ['nullable', 'numeric', 'min:0'],
            'total_deduction' => ['nullable', 'numeric', 'min:0'],
            'allowance_details' => ['nullable', 'array'],
            'allowance_details.*' => ['nullable', 'numeric'], // 수당 항목별 금액 (key: 항목명, value: 금액)
            'deduction_details' => ['nullable', 'array'],
            'deduction_details.*' => ['nullable', 'numeric'], // 공제 항목별 금액 (key: 항목명, value: 금액)
            'payment_date' => ['nullable', 'date'],
            'status' => ['nullable', 'string', 'in:scheduled,completed'],
        ];
    }

    public function messages(): array
    {
        return [
            'employee_id.required' => __('validation.required', ['attribute' => '직원']),
            'employee_id.exists' => __('validation.exists', ['attribute' => '직원']),
            'year.required' => __('validation.required', ['attribute' => '년도']),
            'month.required' => __('validation.required', ['attribute' => '월']),
            'base_salary.required' => __('validation.required', ['attribute' => '기본급']),
        ];
    }
}
