<?php

namespace Database\Factories;

use App\Enums\ApprovalMode;
use App\Enums\EventStatus;
use App\Enums\EventType;
use App\Enums\LocationType;
use App\Enums\ParticipationType;
use App\Enums\PricingType;
use App\Models\Event;
use App\Models\Game;
use App\Models\User;
use App\Support\PublicId;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

/**
 * @extends Factory<Event>
 */
class EventFactory extends Factory
{
    protected $model = Event::class;

    public function definition(): array
    {
        $title = fake()->unique()->sentence(3);

        return [
            'public_id' => PublicId::generate(),
            'game_id' => Game::factory(),
            'created_by' => User::factory()->admin(),
            'title' => $title,
            'slug' => Str::slug($title),
            'short_description' => fake()->sentence(),
            'description' => fake()->paragraph(),
            'event_type' => EventType::Tournament,
            'participation_type' => ParticipationType::Individual,
            'location_type' => LocationType::Online,
            'timezone' => 'UTC',
            'registration_opens_at' => now()->subDay(),
            'registration_closes_at' => now()->addWeek(),
            'starts_at' => now()->addWeeks(2),
            'ends_at' => now()->addWeeks(2)->addHours(6),
            'capacity' => 10,
            'waitlist_enabled' => false,
            'approval_mode' => ApprovalMode::Automatic,
            'pricing_type' => PricingType::Free,
            'status' => EventStatus::Published,
            'published_at' => now(),
        ];
    }

    public function registrationOpen(): static
    {
        return $this->state(fn (array $attributes) => [
            'status' => EventStatus::RegistrationOpen,
            'registration_opens_at' => now()->subDay(),
            'registration_closes_at' => now()->addWeek(),
            'published_at' => now(),
        ]);
    }

    public function paid(int $feeMinor = 5000, string $currency = 'EGP'): static
    {
        return $this->state(fn (array $attributes) => [
            'pricing_type' => PricingType::Paid,
            'fee_amount_minor' => $feeMinor,
            'currency' => $currency,
        ]);
    }
}
