<?php

declare(strict_types=1);

namespace Database\Factories;

use App\Models\User;
use App\Models\WinbackCampaign;
use Illuminate\Database\Eloquent\Factories\Factory;

/** @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\WinbackRecipient> */
class WinbackRecipientFactory extends Factory
{
    /** @return array<string, mixed> */
    public function definition(): array
    {
        return [
            'campaign_id' => WinbackCampaign::factory(),
            'user_id' => User::factory(),
            'subscription_id' => null,
            'current_email_index' => 0,
            'last_email_sent_at' => null,
            'opened_count' => 0,
            'clicked_count' => 0,
            'reactivated' => false,
            'reactivated_at' => null,
            'unsubscribed_at' => null,
        ];
    }

    public function reactivated(): static
    {
        return $this->state(fn (array $attributes): array => [
            'reactivated' => true,
            'reactivated_at' => now(),
        ]);
    }

    public function unsubscribed(): static
    {
        return $this->state(fn (array $attributes): array => [
            'unsubscribed_at' => now(),
        ]);
    }

    public function withEmailsSent(int $count = 1): static
    {
        return $this->state(fn (array $attributes): array => [
            'current_email_index' => $count,
            'last_email_sent_at' => now()->subDays(2),
        ]);
    }
}
