<?php

declare(strict_types=1);

namespace Database\Factories;

use App\Models\LeadCharge;
use App\Models\Tenant;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends Factory<LeadCharge>
 */
class LeadChargeFactory extends Factory
{
    protected $model = LeadCharge::class;

    public function definition(): array
    {
        // Factory НЕ создаёт реальный Deal автоматически — composite FK
        // requires (deal_id, deal_received_at) пары; тесты, требующие FK-целостность,
        // явно создают Deal::factory() и передают пару в state().
        return [
            'tenant_id' => Tenant::factory(),
            'deal_id' => fake()->numberBetween(1, 99999),
            'deal_received_at' => now(),
            'tier_no' => fake()->numberBetween(1, 7),
            'price_per_lead_kopecks' => fake()->numberBetween(2000, 6000),
            'charge_source' => 'rub',
            'charged_at' => now(),
            'created_at' => now(),
        ];
    }

    /**
     * State для prepaid-списания (price=0).
     */
    public function prepaid(): self
    {
        return $this->state(fn () => [
            'charge_source' => 'prepaid',
            'price_per_lead_kopecks' => 0,
        ]);
    }
}
