<?php

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::create('commission_defaults', function (Blueprint $table) {
            $table->id();
            // Foreign key to the insurers table
            $table->foreignId('insurer_id')->constrained('insurers')->cascadeOnDelete();
            // Foreign key to the insurance_types table
            $table->foreignId('insurance_type_id')->constrained('insurance_types')->cascadeOnDelete();
            // Commission percentage (e.g. 10.00 for 10%)
            $table->decimal('commission_rate', 5, 2);
            $table->timestamps();

            // Ensure each insurer/insurance_type pair is unique.
            $table->unique(['insurer_id', 'insurance_type_id']);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('commission_defaults');
    }
};
