<?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\Order> */
class OrderFactory extends Factory
{
    /** @return array<string, mixed> */
    public function definition(): array
    {
        return [
            'user_id' => User::factory(),
            'plan_id' => Plan::factory(),
            'order_number' => 'ORD-'.strtoupper(fake()->unique()->bothify('########')),
            'status' => fake()->randomElement(['pending', 'processing', 'completed', 'cancelled']),
            'total' => fake()->randomFloat(2, 5, 200),
            'currency' => 'USD',
            'payment_gateway' => fake()->randomElement(['stripe', 'paypal']),
            'configuration' => ['hostname' => fake()->domainWord().'.ezscale.cloud'],
        ];
    }

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

    public function processing(): static
    {
        return $this->state(fn () => ['status' => 'processing']);
    }

    public function completed(): static
    {
        return $this->state(fn () => ['status' => 'completed', 'completed_at' => now()]);
    }

    public function cancelled(): static
    {
        return $this->state(fn () => ['status' => 'cancelled', 'cancelled_at' => now()]);
    }
}
