<?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::disableForeignKeyConstraints();

        if (Schema::hasColumn('basket_items', 'prescription_item_id')) {
            Schema::table('basket_items', function (Blueprint $table) {
                $table->dropColumn(['prescription_item_id', 'nhs_prescription']);
            });
        }

        if (Schema::hasColumn('order_items', 'prescription_item_id')) {
            Schema::table('order_items', function (Blueprint $table) {
                $table->dropColumn(['prescription_item_id', 'nhs_prescription']);
            });
        }

        if (Schema::hasColumn('order_archive_items', 'nhs_prescription')) {
            Schema::table('order_archive_items', function (Blueprint $table) {
                $table->dropColumn('nhs_prescription');
            });
        }

        Schema::dropIfExists('nhs_members_nhs_medical_categories');
        Schema::dropIfExists('nhs_member_prescriptions');
        Schema::dropIfExists('nhs_prescription_items');
        Schema::dropIfExists('nhs_prescriptions');
        Schema::dropIfExists('nhs_member_doctor_surgeries');
        Schema::dropIfExists('nhs_reminders');
        Schema::dropIfExists('nhs_members');
        Schema::dropIfExists('nhs_unilexicon_products');
        Schema::dropIfExists('nhs_dosages');
        Schema::dropIfExists('nhs_medical_categories');
        Schema::dropIfExists('nhs_medications');

        Schema::enableForeignKeyConstraints();
    }

    public function down(): void
    {
        // Intentionally not implemented — NHS module has been permanently removed.
    }
};
