<?php

namespace Functional\Streaks\Database\Factories;

use Functional\Streaks\Models\Streak;
use Functional\Users\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends Factory<Streak>
 */
class StreakFactory extends Factory
{
    protected $model = Streak::class;

    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        $current = fake()->numberBetween(0, 60);

        return [
            'user_id' => User::factory(),
            'current_count' => $current,
            'longest_count' => max($current, fake()->numberBetween(0, 120)),
            'last_active_date' => $current > 0
                ? fake()->dateTimeBetween('-2 days', 'now')->format('Y-m-d')
                : null,
            'freezes_available' => fake()->numberBetween(0, 3),
            'freeze_last_granted_on' => fake()->optional(0.4)->dateTimeBetween('-30 days', 'now')?->format('Y-m-d'),
        ];
    }
}
