<?php

namespace Functional\Tracking\Database\Factories;

use Functional\Exercises\Models\Exercise;
use Functional\Tracking\Models\SetLog;
use Functional\Tracking\Models\WorkoutSession;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends Factory<SetLog>
 */
class SetLogFactory extends Factory
{
    protected $model = SetLog::class;

    /**
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        return [
            'workout_session_id' => WorkoutSession::factory(),
            'exercise_id' => Exercise::factory(),
            'set_number' => fake()->numberBetween(1, 5),
            'reps' => fake()->numberBetween(4, 15),
            'weight' => fake()->randomFloat(2, 5, 150),
            'rpe' => fake()->randomFloat(1, 6, 10),
            'duration_seconds' => null,
            'distance_meters' => null,
            'is_warmup' => false,
            'is_completed' => true,
            'logged_at' => fake()->dateTimeBetween('-2 months', 'now'),
        ];
    }

    /** Série d'échauffement, plus légère. */
    public function warmup(): static
    {
        return $this->state(fn (array $attributes) => [
            'is_warmup' => true,
            'weight' => fake()->randomFloat(2, 5, 40),
        ]);
    }

    /** Série démarrée mais non terminée par l'utilisateur. */
    public function incomplete(): static
    {
        return $this->state(fn (array $attributes) => [
            'is_completed' => false,
        ]);
    }

    /** Série cardio (course, rameur...) : durée/distance plutôt que reps/poids. */
    public function cardio(): static
    {
        return $this->state(fn (array $attributes) => [
            'reps' => null,
            'weight' => null,
            'rpe' => null,
            'duration_seconds' => fake()->numberBetween(60, 3600),
            'distance_meters' => fake()->randomFloat(2, 200, 10000),
        ]);
    }
}
