<?php
namespace Database\Factories;
use App\Modules\Promotions\Models\LoyaltyTransaction;
use App\Modules\User\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
class LoyaltyTransactionFactory extends Factory
{
protected $model = LoyaltyTransaction::class;
public function definition(): array
{
$points = fake()->numberBetween(10, 500);
return [
'user_id' => User::factory(),
'type' => 'earn',
'points' => $points,
'balance_after' => $points,
'reference_type' => null,
'reference_id' => null,
'description' => 'Points earned',
'expires_at' => now()->addYear(),
];
}
public function earn(int $points = 100): static
{
return $this->state([
'type' => 'earn',
'points' => $points,
]);
}
public function burn(int $points = 50): static
{
return $this->state([
'type' => 'burn',
'points' => -$points,
]);
}
public function expired(): static
{
return $this->state([
'expires_at' => now()->subDay(),
]);
}
}