<?php

namespace Database\Factories;

use App\Enums\RedemptionStatus;
use App\Models\Redemption;
use App\Models\Reward;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

class RedemptionFactory extends Factory
{
    protected $model = Redemption::class;

    public function definition(): array
    {
        return [
            'user_id' => User::factory(),
            'reward_id' => Reward::factory(),
            'code' => Str::upper(Str::random(10)),
            'points_spent' => 100,
            'status' => RedemptionStatus::WAITING_PICKUP,
            'expires_at' => $this->faker->dateTimeBetween('+1 week', '+1 month'),
        ];
    }

    public function verified(User $verifier): Factory
    {
        return $this->state(fn () => [
            'status' => RedemptionStatus::PICKED_UP,
            'verified_at' => now(),
            'verified_by' => $verifier->id,
        ]);
    }

    public function expired(): Factory
    {
        return $this->state(fn () => [
            'status' => RedemptionStatus::EXPIRED,
        ]);
    }
}
