<?php

use Functional\Tracking\Enums\WorkoutSessionStatus;
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_sessions', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained();
            $table->foreignId('routine_id')->nullable()->constrained();      // séance issue d'une routine (optionnel)
            $table->foreignId('program_id')->nullable()->constrained();     // séance issue d'un programme (optionnel)
            $table->string('title')->nullable();
            $table->dateTime('started_at');
            $table->dateTime('ended_at')->nullable();
            $table->string('status')->default(WorkoutSessionStatus::Active->value)->index();
            $table->text('notes')->nullable();
            $table->decimal('total_volume', 10, 2)->nullable();          // somme reps*poids calculée à la complétion
            $table->timestamps();
        });
    }

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