<?php

declare(strict_types=1);

namespace App\Http\Requests\NovaCards;

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

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

    public function rules(): array
    {
        return [
            'slug' => ['required', 'string', 'max:140', 'regex:/^[a-z0-9]+(?:-[a-z0-9]+)*$/'],
            'title' => ['required', 'string', 'max:140'],
            'description' => ['nullable', 'string', 'max:1000'],
            'prompt' => ['nullable', 'string', 'max:1000'],
            'rules_json' => ['nullable', 'array'],
            'status' => ['required', Rule::in(['draft', 'active', 'completed', 'archived'])],
            'official' => ['sometimes', 'boolean'],
            'featured' => ['sometimes', 'boolean'],
            'winner_card_id' => ['nullable', 'integer', 'exists:nova_cards,id'],
            'starts_at' => ['nullable', 'date'],
            'ends_at' => ['nullable', 'date', 'after_or_equal:starts_at'],
        ];
    }
}