<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('token_devices', function (Blueprint $table) {
            $table->id();
            $table->string('uuid')->index();
            $table->integer('orden')->nullable();
            $table->boolean('estado')->default(true);

            //? PersonalAccessToken
            $table->unsignedBigInteger('personal_access_token_id');
            $table->foreign('personal_access_token_id')
                ->references('id')
                ->on('personal_access_tokens')
                ->onDelete('cascade');

            //? Devices
            $table->unsignedBigInteger('device_id');
            $table->foreign('device_id')
                ->references('id')
                ->on('devices')->onDelete('cascade');

            //? DevicesOperativeSystems
            $table->unsignedBigInteger('device_operative_system_id');
            $table->foreign('device_operative_system_id', 'fk_os')
                ->references('id')
                ->on('devices_operative_systems')
                ->onDelete('cascade');

            //? Browsers
            $table->unsignedBigInteger('browser_id');
            $table->foreign('browser_id')->references('id')
                ->on('browsers')
                ->onDelete('cascade');

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

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