<?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('claim_institution', function (Blueprint $table) {
            $table->foreignId('record_type_id')
                ->nullable()
                ->after('institution_id')
                ->constrained('institution_record_types')
                ->nullOnDelete();
            $table->string('dates')->nullable()->after('record_type_id');
        });
    }

    public function down(): void {
        Schema::table('claim_institution', function (Blueprint $table) {
            $table->dropForeign(['record_type_id']);
            $table->dropColumn(['record_type_id', 'dates']);
            $table->unique(['claim_id', 'institution_id']);
        });
    }
};
