*/ final class EmailLogFactory extends Factory { protected $model = EmailLog::class; public function definition(): array { $type = fake()->randomElement(EmailTemplateType::cases()); return [ 'organisation_id' => Organisation::factory(), 'event_id' => null, 'person_id' => null, 'user_id' => null, 'recipient_email' => fake()->safeEmail(), 'recipient_name' => fake()->name(), 'mailable_class' => TransactionalMail::class, 'template_type' => $type->value, 'subject' => fake()->sentence(), 'status' => EmailLogStatus::QUEUED->value, 'queued_at' => now(), 'triggered_by_user_id' => null, ]; } public function sent(): static { return $this->state(fn () => [ 'status' => EmailLogStatus::SENT->value, 'sent_at' => now(), ]); } public function failed(): static { return $this->state(fn () => [ 'status' => EmailLogStatus::FAILED->value, 'failed_at' => now(), 'error_message' => 'Connection refused', ]); } }