<?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('service_songs', function (Blueprint $table) {
            $table->id();
            $table->foreignId('service_id')->constrained()->cascadeOnDelete();
            $table->foreignId('song_id')->nullable()->constrained()->nullOnDelete();
            $table->foreignId('song_arrangement_id')->nullable()->constrained()->nullOnDelete();
            $table->boolean('use_translation')->default(false);
            $table->unsignedInteger('order');
            $table->string('cts_song_name');
            $table->string('cts_ccli_id')->nullable()->index();
            $table->timestamp('matched_at')->nullable();
            $table->timestamp('request_sent_at')->nullable();
            $table->timestamps();

            $table->index('service_id');
            $table->index(['service_id', 'order']);
        });
    }

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