<?php

namespace App\Http\Requests\Hr;

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

class StoreSalaryStructureRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()?->hasPermission('payroll.salary.edit') === true;
    }

    public function rules(): array
    {
        $tenantId = $this->user()->tenant_id;

        return [
            'effective_from' => ['required', 'date'],
            'basic_salary' => ['required', 'numeric', 'min:0.01', 'max:999999999'],
            'housing_allowance' => ['nullable', 'numeric', 'min:0'],
            'transport_allowance' => ['nullable', 'numeric', 'min:0'],
            'other_fixed_allowance' => ['nullable', 'numeric', 'min:0'],
            'variable_allowance' => ['nullable', 'numeric', 'min:0'],
            'overtime_eligible' => ['nullable', 'boolean'],
            'overtime_hourly_rate' => ['nullable', 'numeric', 'min:0'],
            'currency' => ['nullable', Rule::in(['AED'])],
            'payment_method' => ['required', Rule::in(['bank_transfer', 'cash', 'cheque', 'wps'])],
            'payroll_group_id' => ['nullable', Rule::exists('payroll_groups', 'id')->where('tenant_id', $tenantId)],
            'change_reason' => ['required', 'string', 'min:5', 'max:1000'],
            'bank_name' => ['nullable', 'string', 'max:150'],
            'account_holder' => ['nullable', 'string', 'max:150'],
            'iban' => ['nullable', 'string', 'max:50'],
            'account_number' => ['nullable', 'string', 'max:80'],
            'routing_code' => ['nullable', 'string', 'max:80'],
            'wps_employee_id' => ['nullable', 'string', 'max:80'],
        ];
    }
}
