<?php

declare(strict_types=1);

namespace Database\Factories;

use App\Enums\TldType;
use App\Models\Tld;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends Factory<Tld>
 */
class TldFactory extends Factory
{
    protected $model = Tld::class;

    /** @return array<string, mixed> */
    public function definition(): array
    {
        return [
            'tld' => fake()->unique()->lexify('???'),
            'name' => fake()->word(),
            'type' => TldType::Gtld,
            'is_active' => true,
            'listing_enabled' => true,
            'is_transferable' => true,
            'supports_auth_code' => true,
            'transfer_lock_days' => 60,
            'registration_fee_minor' => 1299,
            'renewal_fee_minor' => 1499,
            'transfer_fee_minor' => 1099,
            'currency' => 'USD',

            // Explicit nullables, so a created model matches a retrieved one.
            'registry' => null,
            'whois_server' => null,
            'rdap_url' => null,
            'metadata' => null,
            'deleted_at' => null,
        ];
    }

    public function com(): static
    {
        return $this->state(fn (): array => [
            'tld' => 'com',
            'name' => 'Commercial',
            'is_premium' => true,
        ]);
    }

    /** A TLD with no viable registrar-to-registrar transfer path. */
    public function untransferable(): static
    {
        return $this->state(fn (): array => [
            'is_transferable' => false,
            'supports_auth_code' => false,
            'listing_enabled' => false,
        ]);
    }
}
