<?php

declare(strict_types=1);

namespace App\Http\Requests\NovaCards;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class AdminStoreNovaCardTemplateRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user() !== null;
    }

    public function rules(): array
    {
        return [
            'slug' => ['required', 'string', 'max:120', 'regex:/^[a-z0-9]+(?:-[a-z0-9]+)*$/'],
            'name' => ['required', 'string', 'max:160'],
            'description' => ['nullable', 'string', 'max:400'],
            'preview_image' => ['nullable', 'string', 'max:255'],
            'config_json' => ['required', 'array'],
            'supported_formats' => ['required', 'array', 'min:1'],
            'supported_formats.*' => ['string', Rule::in(array_keys((array) config('nova_cards.formats', [])))],
            'active' => ['sometimes', 'boolean'],
            'official' => ['sometimes', 'boolean'],
            'order_num' => ['sometimes', 'integer', 'min:0', 'max:9999'],
        ];
    }
}