<?php

declare(strict_types=1);

namespace Database\Factories;

use App\Models\Affiliate;
use App\Models\AffiliatePayout;
use Illuminate\Database\Eloquent\Factories\Factory;

/** @extends Factory<AffiliatePayout> */
class AffiliatePayoutFactory extends Factory
{
    protected $model = AffiliatePayout::class;

    /** @return array<string, mixed> */
    public function definition(): array
    {
        return [
            'affiliate_id' => Affiliate::factory(),
            'amount' => fake()->randomFloat(2, 50, 500),
            'currency' => 'USD',
            'method' => fake()->randomElement(['credit', 'paypal', 'bank_transfer']),
            'status' => 'pending',
        ];
    }

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

    public function completed(): static
    {
        return $this->state(fn (): array => [
            'status' => 'completed',
            'processed_at' => now(),
            'reference' => 'PAY-'.strtoupper(fake()->bothify('########')),
        ]);
    }

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