<?php

declare(strict_types=1);

namespace Database\Factories;

use App\Models\Affiliate;
use App\Models\AffiliateCommission;
use App\Models\AffiliateReferral;
use Illuminate\Database\Eloquent\Factories\Factory;

/** @extends Factory<AffiliateCommission> */
class AffiliateCommissionFactory extends Factory
{
    protected $model = AffiliateCommission::class;

    /** @return array<string, mixed> */
    public function definition(): array
    {
        return [
            'affiliate_id' => Affiliate::factory(),
            'referral_id' => AffiliateReferral::factory(),
            'payment_transaction_id' => null,
            'amount' => fake()->randomFloat(2, 1, 50),
            'currency' => 'USD',
            'type' => fake()->randomElement(['signup', 'renewal']),
            'status' => 'pending',
        ];
    }

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

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

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

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

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