<?php

use App\Models\Competition;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('competitions', function (Blueprint $table) {
            $table->string('notice_id', 100)->nullable()->after('wa_id');
            $table->unsignedBigInteger('updated_competition_id')->nullable()->after('wa_id');
            $table->string('updated_competition_url', 255)->nullable()->after('updated_competition_id');
            $table->string('updated_notice_id', 100)->nullable()->after('updated_competition_url');
            $table->string('competition_url', 255)->nullable()->after('html_url');

            $table->foreign('updated_competition_id')
                ->references('id')
                ->on('competitions')
                ->onDelete('set null');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('competitions', function (Blueprint $table) {
            $table->dropForeign(['updated_competition_id']);
            $table->dropColumn('updated_competition_id');
            $table->dropColumn('updated_competition_url');
            $table->dropColumn('updated_notice_id');
            $table->dropColumn('competition_url');
            $table->dropColumn('notice_id');
        });
    }
};
