<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

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

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            'gallery_type_id' => 'required|exists:gallery_types,id',
            'title'           => 'required|string|max:191',
            'description'     => 'nullable|string|max:2000',
            'is_published'    => 'nullable|boolean',
        ];
    }

    /**
     * Get custom error messages.
     */
    public function messages(): array
    {
        return [
            'gallery_type_id.required' => 'Please select a gallery type.',
            'gallery_type_id.exists'   => 'The selected gallery type is invalid.',
            'title.required'           => 'Gallery title is required.',
        ];
    }
}
