<?php

namespace App\Http\Requests\Events;

use Illuminate\Foundation\Http\FormRequest;

class StoreEventRegistrationRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()?->can('create', \App\Models\EventRegistration::class) ?? false;
    }

    public function rules(): array
    {
        $needsPhone = blank($this->user()?->phone_e164);

        return [
            'player_game_profile_id' => ['required', 'integer', 'exists:player_game_profiles,id'],
            'contact_name' => ['required', 'string', 'max:255'],
            'contact_email' => ['required', 'email', 'max:255'],
            'contact_whatsapp' => ['nullable', 'boolean'],
            'user_notes' => ['nullable', 'string', 'max:2000'],
            'phone_country_code' => [$needsPhone ? 'required' : 'nullable', 'string', 'max:5'],
            'phone' => [$needsPhone ? 'required' : 'nullable', 'string', 'max:20'],
        ];
    }
}
