<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class StoreGalleryTypeRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return auth()->user()->can('create gallery types');
    }

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            'name'        => 'required|string|max:191|unique:gallery_types,name',
            'description' => 'nullable|string|max:1000',
            'color'       => 'nullable|string|regex:/^#[A-Fa-f0-9]{6}$/',
            'icon'        => 'nullable|string|max:191',
            'is_active'   => 'nullable|boolean',
        ];
    }

    /**
     * Get custom error messages.
     */
    public function messages(): array
    {
        return [
            'name.required'       => 'Gallery type name is required.',
            'name.unique'         => 'A gallery type with this name already exists.',
            'color.regex'         => 'Color must be a valid hex color code (e.g., #3b82f6).',
        ];
    }
}
