<?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_agenda_items', function (Blueprint $table) {
            $table->id();
            $table->foreignId('service_id')->constrained()->cascadeOnDelete();
            $table->string('cts_agenda_item_id')->nullable()->index();
            $table->string('position');
            $table->string('title');
            $table->string('type');
            $table->text('note')->nullable();
            $table->string('duration')->nullable();
            $table->string('start')->nullable();
            $table->boolean('is_before_event')->default(false);
            $table->json('responsible')->nullable();
            $table->foreignId('service_song_id')->nullable()->constrained()->nullOnDelete();
            $table->unsignedInteger('sort_order');
            $table->timestamps();

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

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