<?php

declare(strict_types=1);

namespace Database\Factories;

use App\Models\CreditNote;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;

/** @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\CreditNote> */
class CreditNoteFactory extends Factory
{
    /** @return array<string, mixed> */
    public function definition(): array
    {
        return [
            'user_id' => User::factory(),
            'number' => CreditNote::generateNumber(),
            'amount' => fake()->randomFloat(2, 5, 200),
            'currency' => 'USD',
            'reason' => fake()->sentence(),
            'status' => 'issued',
            'issued_at' => now(),
        ];
    }

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

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