<?php

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

/**
 * PRC-1143 — konsolide şema: `affiliate_product_overrides` tablosunun TAM tanımı (tek dosya).
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::create('affiliate_product_overrides', function (Blueprint $t) {
            $t->id();
            $t->unsignedBigInteger('product_id');
            $t->decimal('commission_rate', 5, 2)->nullable();
            $t->boolean('enabled')->default(1);
            $t->timestamp('created_at')->nullable();
            $t->timestamp('updated_at')->nullable();
            $t->unique('product_id', 'affiliate_product_overrides_product_id_unique');
            $t->foreign('product_id', 'affiliate_product_overrides_product_id_foreign')->references('id')->on('products')->onDelete('cascade');
        });
    }

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