<?php

namespace Database\Factories;

use App\Models\Package;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

class PackageFactory extends Factory
{
    protected $model = Package::class;

    public function definition(): array
    {
        $name = $this->faker->word();

        return [
            'name' => $name,
            'slug' => Str::slug($name.'-'.uniqid()),
            'description' => $this->faker->sentence(),
            'price' => $this->faker->randomFloat(2, 0, 100),
            'max_photos' => $this->faker->numberBetween(100, 1000),
            'max_guests' => $this->faker->numberBetween(50, 500),
            'gallery_days' => $this->faker->numberBetween(7, 30),
            'max_events_per_year' => $this->faker->numberBetween(1, 10),
            'features' => json_encode([
                'photo_likes_enabled' => $this->faker->boolean(),
                'event_checklist' => $this->faker->boolean(),
                'custom_domain' => $this->faker->boolean(),
                'advanced_analytics' => $this->faker->boolean(),
            ]),
            'type' => $this->faker->randomElement(['endcustomer', 'reseller']),
            'paddle_sync_status' => null,
            'paddle_synced_at' => null,
            'paddle_snapshot' => null,
        ];
    }

    public function free(): static
    {
        return $this->state(fn (array $attributes) => [
            'price' => 0,
        ]);
    }

    public function paid(): static
    {
        return $this->state(fn (array $attributes) => [
            'price' => $this->faker->randomFloat(2, 5, 100),
        ]);
    }

    public function endcustomer(): static
    {
        return $this->state(fn (array $attributes) => [
            'type' => 'endcustomer',
        ]);
    }

    public function reseller(): static
    {
        return $this->state(fn (array $attributes) => [
            'type' => 'reseller',
        ]);
    }
}
