<?php

namespace App\Http\Requests\ItemCategory;

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

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

    public function rules(): array
    {
        $current = $this->route('item_category');
        $currentId = $current ? $current->id : null;

        return [
            'name' => [
                'required', 'string', 'max:255',
                Rule::unique('chart_of_accounts', 'name')->ignore($currentId),
            ],
            'parent_category_id' => [
                'nullable', 'integer', 'exists:chart_of_accounts,id',
                Rule::notIn([$currentId]),
            ],
            'is_active' => [
                'sometimes', 'boolean'
            ],
        ];
    }
}
