<?php

declare(strict_types=1);

namespace Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;

/** @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\WinbackCampaign> */
class WinbackCampaignFactory extends Factory
{
    /** @return array<string, mixed> */
    public function definition(): array
    {
        return [
            'name' => fake()->words(3, true).' Campaign',
            'cancellation_reason' => fake()->randomElement([
                'Too expensive',
                'No longer needed',
                'Switching to competitor',
                'Poor performance',
                'Missing features',
                'Technical issues',
                null,
            ]),
            'email_sequence' => [
                [
                    'delay_days' => 1,
                    'subject' => 'We miss you!',
                    'body' => 'We noticed you cancelled your subscription. We would love to have you back.',
                ],
                [
                    'delay_days' => 7,
                    'subject' => 'A special offer just for you',
                    'body' => 'Come back and enjoy a special discount on your next subscription.',
                ],
            ],
            'offer_type' => fake()->randomElement(['discount', 'credit', 'free_upgrade', 'none']),
            'offer_value' => fake()->optional(0.7)->randomFloat(2, 5, 50),
            'offer_duration_days' => fake()->optional(0.5)->numberBetween(7, 90),
            'coupon_code' => fake()->optional(0.3)->bothify('WINBACK-##??'),
            'status' => 'active',
        ];
    }

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

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

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

    public function forReason(string $reason): static
    {
        return $this->state(fn (array $attributes): array => [
            'cancellation_reason' => $reason,
        ]);
    }

    public function catchAll(): static
    {
        return $this->state(fn (array $attributes): array => [
            'cancellation_reason' => null,
        ]);
    }

    public function withDiscount(float $value = 20.00): static
    {
        return $this->state(fn (array $attributes): array => [
            'offer_type' => 'discount',
            'offer_value' => $value,
            'offer_duration_days' => 30,
            'coupon_code' => 'COMEBACK20',
        ]);
    }
}
