<?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_exercises', function (Blueprint $table) {
            $table->id();
            $table->foreignId('workout_session_id')->constrained('workout_sessions')->cascadeOnDelete();

            // فقط ارجاع — نام/GIF/عضله همیشه زنده از Exercise خوانده می‌شود (بند ۲۱)
            $table->foreignId('exercise_id')->constrained('exercises')->restrictOnDelete();

            $table->unsignedInteger('sort_order')->default(0);

            $table->unsignedTinyInteger('sets')->nullable();
            $table->string('reps', 20)->nullable();          // می‌تواند بازه باشد، مثل "8-12"
            $table->decimal('weight_kg', 6, 2)->nullable();
            $table->string('intensity', 50)->nullable();      // «توان» — سطح شدت/RPE، متن آزاد
            $table->decimal('one_rm', 6, 2)->nullable();       // 1RM
            $table->decimal('percent_one_rm', 5, 2)->nullable(); // درصد 1RM
            $table->string('tempo', 20)->nullable();           // مثل "3-1-2-0"
            $table->unsignedSmallInteger('rest_seconds')->nullable();
            $table->text('coach_notes')->nullable();

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

            $table->index(['workout_session_id', 'sort_order']);
        });
    }

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