<?php

namespace Functional\Tracking\Database\Factories;

use Functional\Exercises\Models\Exercise;
use Functional\Tracking\Enums\PersonalRecordType;
use Functional\Tracking\Models\PersonalRecord;
use Functional\Users\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends Factory<PersonalRecord>
 */
class PersonalRecordFactory extends Factory
{
    protected $model = PersonalRecord::class;

    /**
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        return [
            'user_id' => User::factory(),
            'exercise_id' => Exercise::factory(),
            'type' => fake()->randomElement(PersonalRecordType::cases()),
            'value' => fake()->randomFloat(2, 20, 250),
            'unit' => 'kg',
            'achieved_at' => fake()->dateTimeBetween('-1 year', 'now'),
            'workout_session_id' => null,
        ];
    }

    /** Record de charge maximale à une répétition. */
    public function oneRepMax(): static
    {
        return $this->state(fn (array $attributes) => [
            'type' => PersonalRecordType::OneRepMax,
            'unit' => 'kg',
        ]);
    }

    /** Record de temps (ex : gainage, sprint chronométré). */
    public function bestTime(): static
    {
        return $this->state(fn (array $attributes) => [
            'type' => PersonalRecordType::BestTime,
            'value' => fake()->randomFloat(2, 30, 600),
            'unit' => 'sec',
        ]);
    }
}
