<?php

declare(strict_types=1);

namespace Cone\Bazar\Database\Factories;

use Cone\Bazar\Models\Transaction;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Date;

/**
 * @template TModel of \Illuminate\Database\Eloquent\Model
 */
class TransactionFactory extends Factory
{
    /**
     * The name of the factory's corresponding model.
     *
     * @var class-string<\Illuminate\Database\Eloquent\Model>
     */
    protected $model = Transaction::class;

    /**
     * Get the name of the model that is generated by the factory.
     *
     * @return class-string<\Illuminate\Database\Eloquent\Model|TModel>
     */
    public function modelName(): string
    {
        return $this->model::getProxiedClass();
    }

    /**
     * Define the model's default state.
     */
    public function definition(): array
    {
        return [
            'driver' => 'cash',
            'amount' => mt_rand(10, 1000),
            'type' => Transaction::PAYMENT,
        ];
    }

    /**
     * Configure the refund state.
     */
    public function refund(): static
    {
        return $this->state(function (): array {
            return [
                'type' => Transaction::REFUND,
            ];
        });
    }

    /**
     * Configure the completed state.
     */
    public function completed(): static
    {
        return $this->state(function (): array {
            return [
                'completed_at' => Date::now(),
            ];
        });
    }
}
