<?php
namespace Database\Factories;
use App\Modules\Promotions\Models\GiftCard;
use Illuminate\Database\Eloquent\Factories\Factory;
class GiftCardFactory extends Factory
{
protected $model = GiftCard::class;
public function definition(): array
{
$amount = fake()->randomFloat(2, 100, 2000);
return [
// code is auto-generated by model booted() hook
'amount' => $amount,
'balance' => $amount,
'currency' => 'NPR',
'status' => 'active',
'expires_at' => now()->addYear(),
'purchased_by_user_id' => null,
'redeemed_by_user_id' => null,
'recipient_email' => null,
'recipient_name' => null,
'personal_message' => null,
'order_id' => null,
];
}
public function active(): static
{
return $this->state(['status' => 'active']);
}
public function partiallyUsed(float $remaining): static
{
return $this->state([
'balance' => $remaining,
'status' => 'partially_used',
]);
}
public function fullyUsed(): static
{
return $this->state([
'balance' => 0,
'status' => 'fully_used',
]);
}
public function expired(): static
{
return $this->state([
'expires_at' => now()->subDay(),
'status' => 'expired',
]);
}
}