<?php

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

return new class extends Migration
{
    /**
     * Relax the `part_type` enum to a plain string so any controller-validated
     * value (including the new 'abspann' part type) is accepted across MySQL and
     * SQLite. The enum previously rejected 'abspann' via a MySQL enum definition
     * or a SQLite check-constraint.
     */
    public function up(): void
    {
        Schema::table('macro_assignments', function (Blueprint $table) {
            $table->string('part_type')->change();
        });

        Schema::table('service_macro_overrides', function (Blueprint $table) {
            $table->string('part_type')->change();
        });

        Schema::table('service_macro_assignments', function (Blueprint $table) {
            $table->string('part_type')->change();
        });
    }

    /**
     * Best-effort restore of the original enum. Any 'abspann' rows would be lost
     * on downgrade; a lossy down is acceptable for this local/dev project.
     */
    public function down(): void
    {
        $original = ['information', 'moderation', 'sermon', 'song', 'agenda_item'];

        Schema::table('macro_assignments', function (Blueprint $table) use ($original) {
            $table->enum('part_type', $original)->change();
        });

        Schema::table('service_macro_overrides', function (Blueprint $table) use ($original) {
            $table->enum('part_type', $original)->change();
        });

        Schema::table('service_macro_assignments', function (Blueprint $table) use ($original) {
            $table->enum('part_type', $original)->change();
        });
    }
};
