<?php

namespace Database\Factories;

use App\Models\Membership;
use App\Models\Tier;
use App\Models\User;
use DateTime;
use Illuminate\Database\Eloquent\Factories\Factory;

class MembershipFactory extends Factory
{
    protected $model = Membership::class;

    public function definition(): array
    {
        return [
            'user_id' => User::factory(),
            'tier_id' => Tier::factory(),
            'total_spending' => $this->faker->numberBetween(0, 5000000),
            'reward_points' => $this->faker->numberBetween(0, 1000),
        ];
    }

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