<?php

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

/**
 * PRC-1143 — konsolide şema: `product_contracts` tablosunun TAM tanımı (tek dosya).
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::create('product_contracts', function (Blueprint $t) {
            $t->id();
            $t->unsignedBigInteger('product_id');
            $t->unsignedBigInteger('contract_id');
            $t->boolean('required')->default(1);
            $t->timestamp('created_at')->nullable();
            $t->timestamp('updated_at')->nullable();
            $t->index('contract_id', 'product_contracts_contract_id_foreign');
            $t->unique(['product_id', 'contract_id'], 'product_contracts_product_id_contract_id_unique');
            $t->foreign('contract_id', 'product_contracts_contract_id_foreign')->references('id')->on('contracts')->onDelete('cascade');
            $t->foreign('product_id', 'product_contracts_product_id_foreign')->references('id')->on('products')->onDelete('cascade');
        });
    }

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