<?php

namespace App\Http\Requests\Admin;

use Illuminate\Foundation\Http\FormRequest;

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

    public function rules(): array
    {
        $id = $this->route('salary_component') instanceof \App\Models\SalaryComponent
            ? $this->route('salary_component')->id
            : $this->route('salary_component');

        return [
            'name' => ['required', 'string', 'max:255', "unique:salary_components,name,{$id}"],
            'type' => ['required', 'in:earning,deduction'],
            'status' => ['required', 'in:active,inactive'],
        ];
    }
}
