<?php

namespace Database\Factories;

use App\Enums\ContestStatusEnum;
use App\Enums\DifficultyLevelEnums;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Contest>
 */
class ContestFactory extends Factory
{
    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        return [
            'category_id' => $this->faker->numberBetween(1, 10), // Assuming you have 10 categories
            'image' => $this->faker->imageUrl(640, 480, 'contest', true),
            'start_time' => $this->faker->dateTimeBetween('now', '+1 month'),
            'end_time' => $this->faker->dateTimeBetween('+1 month', '+2 months'),
            'status' => ContestStatusEnum::UPCOMING,
            'contest_level' => $this->faker->randomElement(DifficultyLevelEnums::values()),
            'is_free' => $this->faker->boolean(),
            'entry_fee' => 500,
            'is_featured' => $this->faker->boolean(50), // 50% chance of being featured
            'participant_limit' => $this->faker->numberBetween(50, 500), // Random limit between 50 and 500 participants
        ];
    }

    /**
     * Indicate that the contest is free.
     *
     * @return \Illuminate\Database\Eloquent\Factories\Factory
     */
    public function free(): static
    {
        return $this->state(function (array $attributes) {
            return [
                'is_free' => true,
                'entry_fee' => 0.00,
            ];
        });
    }

    /**
     * Configure the model factory.
     */
    public function configure(): static
    {
        return $this->afterCreating(function ($contest) {
            $contest->translations()->createMany([
                [
                    'locale' => 'en',
                    'title' => $this->faker->sentence(),
                    'description' => $this->faker->paragraph(),
                    'tags' => $this->faker->randomElements(['tag1', 'tag2', 'tag3', 'tag4', 'tag5'], 3),
                ],
                [
                    'locale' => 'bn',
                    'title' => $this->faker->sentence(),
                    'description' => $this->faker->paragraph(),
                    'tags' => $this->faker->randomElements(['tag1', 'tag2', 'tag3', 'tag4', 'tag5'], 3),
                ],
            ]);
            $contest->prizes()->createMany([
                ['name' => 'First Prize', 'amount' => 100.00, 'rank' => 1],
                ['name' => 'Second Prize', 'amount' => 50.00, 'rank' => 2],
                ['name' => 'Third Prize', 'amount' => 25.00, 'rank' => 3],
            ]);
        });
    }
}
