<?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('personal_records', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained();
            $table->foreignId('exercise_id')->constrained();
            $table->string('type')->index();
            $table->decimal('value', 10, 2);
            $table->string('unit');                                             // "kg", "lb", "sec"...
            $table->dateTime('achieved_at');
            $table->foreignId('workout_session_id')->nullable()->constrained(); // séance à l'origine du record (si connue)
            $table->timestamps();

            $table->unique(['user_id', 'exercise_id', 'type']);
        });
    }

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