<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('workout_plans', function (Blueprint $table) {
            $table->id();
            $table->foreignId('athlete_id')->constrained('athletes')->cascadeOnDelete();
            $table->foreignId('coach_id')->constrained('coaches')->cascadeOnDelete();

            $table->string('name', 150);
            $table->foreignId('goal_id')->nullable()->constrained('goals')->nullOnDelete();
            $table->unsignedTinyInteger('duration_weeks')->nullable();
            $table->unsignedTinyInteger('sessions_per_week')->nullable();
            $table->text('description')->nullable();

            $table->enum('status', ['draft', 'active', 'archived'])->default('draft');

            $table->timestamps();
            $table->softDeletes();

            $table->index(['athlete_id', 'status']);
            $table->index(['coach_id', 'status']);
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('workout_plans');
    }
};
