<?php

namespace Modules\Inventory\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
use Modules\Core\Enums\StatusEnum;
use Modules\Core\Traits\FailedValidation;

class InventoryDepartmentRequest extends FormRequest
{
    use FailedValidation;

    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        $departmentId = $this->route('inventory_department');

        return [
            'name' => [
                'required',
                'string',
                'max:255',
                Rule::unique('inventory_departments', 'name')
                    ->ignore($departmentId),
            ],
            'code' => [
                'nullable',
                'string',
                'max:255',
                Rule::unique('inventory_departments', 'code')
                    ->ignore($departmentId),
            ],
            'status' => [
                'required',
                'string',
                Rule::enum(StatusEnum::class),
            ],
        ];
    }
}
