<?php

namespace Functional\Programs\Database\Factories;

use Functional\Programs\Models\Program;
use Functional\Users\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

/**
 * @extends Factory<Program>
 */
class ProgramFactory extends Factory
{
    protected $model = Program::class;

    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        $name = fake()->randomElement([
            'Prise de masse 8 semaines', 'Sèche été', 'Préparation force',
            'Remise en forme progressive', 'Cross-training intensif', 'Retour de blessure',
        ]) . ' ' . fake()->numberBetween(1, 9);

        return [
            'user_id' => User::factory(),
            'name' => $name,
            'slug' => Str::slug($name) . '-' . fake()->unique()->numberBetween(1000, 9999),
            'description' => fake()->boolean(70) ? fake()->sentence(15) : null,
            'duration_weeks' => fake()->numberBetween(4, 16),
            'days_per_week' => fake()->optional(0.8)->numberBetween(2, 6),
            'is_public' => fake()->boolean(25),
        ];
    }

    /** Programme partagé publiquement (visible du catalogue communautaire). */
    public function public(): static
    {
        return $this->state(fn (array $attributes) => ['is_public' => true]);
    }

    /** Programme privé, réservé à son propriétaire. */
    public function private(): static
    {
        return $this->state(fn (array $attributes) => ['is_public' => false]);
    }
}
