<?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_macro_overrides', function (Blueprint $table) {
            $table->id();
            $table->foreignId('service_id')->constrained('services')->cascadeOnDelete();
            $table->enum('part_type', ['information', 'moderation', 'sermon', 'song', 'agenda_item']);
            $table->timestamps();
            $table->unique(['service_id', 'part_type']);
        });

        Schema::create('service_macro_assignments', function (Blueprint $table) {
            $table->id();
            $table->foreignId('service_id')->constrained('services')->cascadeOnDelete();
            $table->enum('part_type', ['information', 'moderation', 'sermon', 'song', 'agenda_item']);
            $table->foreignId('macro_id')->constrained('macros')->restrictOnDelete();
            $table->enum('position', ['all_slides', 'first_slide', 'last_slide', 'by_label']);
            $table->foreignId('label_id')->nullable()->constrained('labels')->restrictOnDelete();
            $table->unsignedInteger('order')->default(0);
            $table->timestamps();
            $table->index(['service_id', 'part_type', 'order']);
        });
    }

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