<?php

namespace Database\Factories;

use App\Enums\PaymentMethod;
use App\Enums\PaymentStatus;
use App\Models\Order;
use App\Models\Payment;
use App\Models\User;
use DateTime;
use Illuminate\Database\Eloquent\Factories\Factory;

class PaymentFactory extends Factory
{
    protected $model = Payment::class;

    public function definition(): array
    {
        return [
            'order_id' => Order::factory(),
            'user_id' => User::factory(),
            'method' => $this->faker->randomElement(PaymentMethod::cases()),
            'amount' => $this->faker->numberBetween(20000, 400000),
        ];
    }

    public function withPaidAt(?DateTime $paidAt = null): Factory
    {
        return $this->state(fn () => ['paid_at' => $paidAt ?? now()]);
    }

    public function withStatus(PaymentStatus $status): Factory
    {
        return $this->state(fn () => ['status' => $status]);
    }

    public function cash(): Factory
    {
        return $this->state(fn () => ['method' => PaymentMethod::CASH]);
    }

    public function transfer(): Factory
    {
        return $this->state(fn () => ['method' => PaymentMethod::TRANSFER]);
    }

    public function paid(): Factory
    {
        return $this->state(fn () => ['status' => PaymentStatus::PAID]);
    }

    public function pending(): Factory
    {
        return $this->state(fn () => ['status' => PaymentStatus::PENDING]);
    }
}
