<?php

namespace App\Http\Requests\V1\Payroll;

use Illuminate\Foundation\Http\FormRequest;

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

    public function rules(): array
    {
        return [
            'user_id' => ['sometimes', 'integer', 'exists:users,id'],
            'pay_year' => ['sometimes', 'integer', 'min:2000', 'max:2100'],
            'pay_month' => ['sometimes', 'integer', 'min:1', 'max:12'],
            'base_salary' => ['sometimes', 'numeric', 'min:0'],
            'overtime_pay' => ['nullable', 'numeric', 'min:0'],
            'bonus' => ['nullable', 'numeric', 'min:0'],
            'allowances' => ['nullable', 'array'],
            'allowances.*.name' => ['required_with:allowances', 'string', 'max:50'],
            'allowances.*.amount' => ['required_with:allowances', 'numeric', 'min:0'],
            'income_tax' => ['nullable', 'numeric', 'min:0'],
            'resident_tax' => ['nullable', 'numeric', 'min:0'],
            'health_insurance' => ['nullable', 'numeric', 'min:0'],
            'pension' => ['nullable', 'numeric', 'min:0'],
            'employment_insurance' => ['nullable', 'numeric', 'min:0'],
            'deductions' => ['nullable', 'array'],
            'deductions.*.name' => ['required_with:deductions', 'string', 'max:50'],
            'deductions.*.amount' => ['required_with:deductions', 'numeric', 'min:0'],
            'note' => ['nullable', 'string', 'max:1000'],
        ];
    }

    public function attributes(): array
    {
        return [
            'user_id' => __('validation.attributes.user_id'),
            'pay_year' => __('validation.attributes.pay_year'),
            'pay_month' => __('validation.attributes.pay_month'),
            'base_salary' => __('validation.attributes.base_salary'),
            'overtime_pay' => __('validation.attributes.overtime_pay'),
            'bonus' => __('validation.attributes.bonus'),
            'allowances' => __('validation.attributes.allowances'),
            'income_tax' => __('validation.attributes.income_tax'),
            'resident_tax' => __('validation.attributes.resident_tax'),
            'health_insurance' => __('validation.attributes.health_insurance'),
            'pension' => __('validation.attributes.pension'),
            'employment_insurance' => __('validation.attributes.employment_insurance'),
            'deductions' => __('validation.attributes.deductions'),
            'note' => __('validation.attributes.note'),
        ];
    }
}
