<?php

namespace Database\Factories;

use App\Models\Payment;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

/** @extends Factory<Payment> */
class PaymentFactory extends Factory
{
    protected $model = Payment::class;

    public function definition(): array
    {
        return [
            'uuid' => (string) Str::uuid(),
            'user_id' => User::factory(),
            'order_id' => 'ORD-'.Str::upper(Str::random(16)),
            'payment_gateway' => 'razorpay',
            'payment_method' => 'upi',
            'amount' => fake()->randomFloat(2, 99, 9999),
            'tax' => 0,
            'discount' => 0,
            'wallet_amount' => 0,
            'currency' => 'INR',
            'status' => 'created',
            'idempotency_key' => (string) Str::uuid(),
            'signature_verified' => false,
            'created_at' => now(),
        ];
    }

    public function paid(): static
    {
        return $this->state(fn (): array => [
            'status' => 'paid',
            'gateway_transaction_id' => 'PAY-'.Str::upper(Str::random(16)),
            'signature_verified' => true,
            'paid_at' => now(),
        ]);
    }
}
