<?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::table('authorised_partners', function (Blueprint $table) {
            $table->foreignId('promoter_id')->nullable()->after('user_id')->constrained()->nullOnDelete();
        });

        Schema::table('courseware_partners', function (Blueprint $table) {
            $table->foreignId('authorised_partner_id')->nullable()->after('user_id')->constrained()->nullOnDelete();
        });

        Schema::dropIfExists('authorised_partner_promoter');
        Schema::dropIfExists('courseware_partner_authorised_partner');
    }

    public function down(): void
    {
        Schema::table('authorised_partners', function (Blueprint $table) {
            $table->dropConstrainedForeignId('promoter_id');
        });

        Schema::table('courseware_partners', function (Blueprint $table) {
            $table->dropConstrainedForeignId('authorised_partner_id');
        });
    }
};
