<?php

namespace Database\Factories;

use App\Models\Client;
use App\Models\Currency;
use App\Models\Invoice;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Invoice>
 */
class InvoiceFactory extends Factory
{
    public function definition(): array
    {
        $subtotal = fake()->randomFloat(2, 10, 500);

        return [
            'client_id' => Client::factory(),
            'currency_id' => Currency::factory(),
            'status' => Invoice::STATUS_UNPAID,
            'invoice_number' => 'INV-' . fake()->unique()->numerify('######'),
            'subtotal' => $subtotal,
            'setup_fee' => 0,
            'tax_amount' => 0,
            'discount_amount' => 0,
            'gateway_fee' => 0,
            'total_amount' => $subtotal,
            'due_date' => now()->addDays(30),
            'issued_at' => now(),
        ];
    }

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

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

    public function paid(): static
    {
        return $this->state([
            'status' => Invoice::STATUS_PAID,
            'paid_date' => now(),
        ]);
    }

    public function withAmount(float $amount): static
    {
        return $this->state([
            'subtotal' => $amount,
            'total_amount' => $amount,
        ]);
    }
}
