<?php

namespace Database\Factories;

use App\Enums\BillingStatus;
use App\Models\Bank;
use App\Models\Billing;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends Factory<Billing>
 */
class BillingFactory extends Factory
{
    public function definition(): array
    {
        $jumlahCredit = fake()->numberBetween(1000, 5000);
        $rate = 100; // RPD §5.2: rate Rp 100/credit

        return [
            'no_invoice' => fake()->unique()->numerify('########'),
            'jumlah_credit' => $jumlahCredit,
            'rate' => $rate,
            'total' => $jumlahCredit * $rate,
            'bank_id' => Bank::factory(),
            'status' => BillingStatus::Pending,
            'payment_method' => 'manual',
            'user_id' => User::factory(),
            'paid_at' => null,
        ];
    }

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