<?php

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

class CreateTrainingWorkoutSectionsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('training_workout_sections', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger("training_workout_id");
            $table->string('description')->nullable();
            $table->integer('seconds')->nullable();
            $table->string('rounds',20)->nullable();
            $table->string('type')->index();
            $table->boolean('custom_score')->default(true);
            $table->string('custom_score_explanation', 300)->nullable();
            $table->timestamps();

            $table->foreign("training_workout_id")->on("training_workouts")->references("id")->onDelete("cascade");

        });

        Schema::table('training_workout_lines',function (Blueprint $table){
            $table->foreign("training_workout_section_id")->references("id")->on("training_workout_sections")->onDelete("cascade"); //si un box es borra, aquest es queda sense idBox
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('training_workout_sections');
    }
}
