<?php

declare(strict_types=1);

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        if (! Schema::hasTable('anime_themes')) {
            Schema::create('anime_themes', function (Blueprint $table) {
                $table->id('theme_id');
                $table->timestamps(6);
                $table->softDeletes(precision: 6);
                $table->integer('type');
                $table->integer('sequence')->nullable();
                $table->string('slug');

                $table->unsignedBigInteger('anime_id');
                $table->foreign('anime_id')->references('anime_id')->on('anime')->cascadeOnDelete();

                $table->unsignedBigInteger('song_id')->nullable();
                $table->foreign('song_id')->references('song_id')->on('songs')->nullOnDelete();
            });
        }
    }
};
