<?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::create('contact_suppressions', function (Blueprint $t) {
            $t->id();
            $t->foreignId('solicitor_id')->constrained()->cascadeOnDelete();
            $t->string('channel', 16);
            $t->string('value');
            $t->string('reason', 64)->nullable();
            $t->nullableMorphs('source');
            $t->timestamp('suppressed_at')->nullable();
            $t->timestamps();

            $t->unique(
                ['solicitor_id', 'channel', 'value'],
                'contact_suppressions_unique'
            );
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('contact_suppressions');
    }
};
