<?php

namespace App\Http\Requests;

use App\Models\ClienteCategoria;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class StoreClienteCategoriaRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()?->can('create', ClienteCategoria::class) ?? false;
    }

    public function rules(): array
    {
        return [
            'code' => ['nullable', 'string', 'max:64', 'alpha_dash', Rule::unique('cliente_categorias', 'code')],
            'name' => ['required', 'string', 'max:255'],
            'color' => ['nullable', 'string', 'regex:/^#[0-9A-Fa-f]{6}$/'],
            'sort_order' => ['nullable', 'integer', 'min:0'],
            'is_active' => ['sometimes', 'boolean'],
        ];
    }
}
