<?php

declare(strict_types=1);

namespace Database\Factories;

use App\Models\Plan;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;

/** @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Service> */
class ServiceFactory extends Factory
{
    /** @return array<string, mixed> */
    public function definition(): array
    {
        $serviceType = fake()->randomElement(['vps', 'dedicated', 'hosting', 'game_server']);
        $platforms = [
            'vps' => 'virtfusion',
            'dedicated' => 'synergycp',
            'hosting' => 'enhance',
            'game_server' => 'pterodactyl',
        ];

        return [
            'user_id' => User::factory(),
            'plan_id' => Plan::factory(),
            'service_type' => $serviceType,
            'platform' => $platforms[$serviceType],
            'platform_service_id' => (string) fake()->numberBetween(1000, 99999),
            'status' => 'active',
            'ipv4_address' => fake()->ipv4(),
            'hostname' => fake()->domainName(),
            'provisioned_at' => now(),
            'auto_renew' => true,
        ];
    }

    public function pending(): static
    {
        return $this->state(fn (array $attributes): array => [
            'status' => 'pending',
            'provisioned_at' => null,
        ]);
    }

    public function suspended(): static
    {
        return $this->state(fn (array $attributes): array => [
            'status' => 'suspended',
            'suspended_at' => now(),
        ]);
    }
}
