<?php

namespace Database\Factories;

use App\Enums\CreditType;
use App\Models\CreditHistory;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends Factory<CreditHistory>
 */
class CreditHistoryFactory extends Factory
{
    public function definition(): array
    {
        return [
            'invoice' => fake()->optional()->numerify('########'),
            'tanggal' => now(),
            'keterangan' => fake()->sentence(),
            'credit' => fake()->numberBetween(100, 1000),
            'jenis' => fake()->randomElement(CreditType::cases()),
            'user_id' => User::factory(),
        ];
    }

    public function in(): static
    {
        return $this->state(fn (array $attributes) => ['jenis' => CreditType::In]);
    }

    public function out(): static
    {
        return $this->state(fn (array $attributes) => ['jenis' => CreditType::Out]);
    }
}
