<?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;
use Modules\Inventory\Enums\UnitTypeEnum;

class UnitRequest extends FormRequest
{
    use FailedValidation;

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

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

        return [
            'name' => [
                'required',
                'string',
                'max:255',
                Rule::unique('units', 'name')->ignore($unitId),
            ],
            'short_name' => [
                'nullable',
                'string',
                'max:255',
                Rule::unique('units', 'short_name')->whereNull('deleted_at')->ignore($unitId),
            ],
            'status' => [
                'required',
                'string',
                Rule::enum(StatusEnum::class),
            ],
        ];
    }
}
