<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

/**
 * Maps each (solicitor, contract) to the Fintrixor template id the solicitor
 * created in their own Fintrixor dashboard. A contract with no row here is not
 * sent through the API (e.g. Part-1/Part-3, handled manually).
 */
return new class extends Migration {
    public function up(): void
    {
        Schema::create('solicitor_contract_templates', function (Blueprint $t) {
            $t->id();
            $t->foreignId('solicitor_id')->constrained()->cascadeOnDelete();
            $t->foreignId('contract_id')->constrained()->cascadeOnDelete();
            $t->string('fintrixor_template_id');
            $t->timestamps();

            $t->unique(['solicitor_id', 'contract_id']);
        });
    }

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