46 lines
1.2 KiB
PHP
46 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Enums\GenerationCreditTransactionType;
|
|
use App\Models\GenerationCreditTransaction;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
/**
|
|
* @extends Factory<GenerationCreditTransaction>
|
|
*/
|
|
class GenerationCreditTransactionFactory extends Factory
|
|
{
|
|
protected $model = GenerationCreditTransaction::class;
|
|
|
|
/**
|
|
* Define the model's default state.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function definition(): array
|
|
{
|
|
return [
|
|
'user_id' => User::factory(),
|
|
'amount' => 1,
|
|
'type' => GenerationCreditTransactionType::AD_REWARD,
|
|
'source_type' => null,
|
|
'source_id' => null,
|
|
'idempotency_key' => fake()->uuid(),
|
|
'daily_reward_key' => 'ad:'.now()->toDateString(),
|
|
'metadata' => null,
|
|
];
|
|
}
|
|
|
|
public function spend(): static
|
|
{
|
|
return $this->state(fn (array $attributes): array => [
|
|
'amount' => -1,
|
|
'type' => GenerationCreditTransactionType::GENERATION_SPEND,
|
|
'idempotency_key' => null,
|
|
'daily_reward_key' => null,
|
|
]);
|
|
}
|
|
}
|