<?php

namespace App\Http\Requests\Admin\Championship;

use App\Enums\ChampionshipMatchStageEnum;
use Illuminate\Foundation\Http\FormRequest;

class StoreChampionshipMatchRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        return [
            'team_a_id' => ['nullable', 'exists:championship_teams,id'],
            'team_b_id' => ['nullable', 'exists:championship_teams,id'],
            'match_date' => ['nullable', 'date'],
            'start_time' => ['nullable', 'date_format:H:i'],
            'end_time' => ['nullable', 'date_format:H:i', 'after:start_time'],
            'court_id' => ['nullable', 'exists:courts,id'],
            'parent_match_id' => ['nullable', 'exists:championship_matches,id'],
            'stage' => ['required', 'integer', 'in:' . implode(',', ChampionshipMatchStageEnum::values())],
            'sort_order' => ['nullable', 'integer', 'min:0'],
        ];
    }
}
