<?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\CategoryTypeEnum;

class CategoryRequest extends FormRequest
{
    use FailedValidation;
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

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

        return [
            'name' => [
                'required',
                'string',
                'max:255',
                Rule::unique('categories', 'name')->ignore($categoryId)->whereNull('deleted_at'),
            ],
            'code' => [
                'required',
                'string',
                'max:50',
                Rule::unique('categories', 'code')->ignore($categoryId),
            ],
            'inventory_department_id' => [
                'required',
                'exists:inventory_departments,id',
            ],
            'description' => ['nullable', 'string', 'max:1000'],
            'category_type' => [
                'required',
                'string',
                Rule::enum(CategoryTypeEnum::class)
            ],

            'has_batch' => ['nullable', 'boolean'],
            'has_expiry' => ['nullable', 'boolean'],

            'status' => [
                'required',
                'string',
                Rule::enum(StatusEnum::class)
            ]
        ];
    }
}
