<?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('customer_pricing', function (Blueprint $table) {
            $table->id(); // Auto-increment primary key
            $table->string('CustomerNo');
            $table->string('ProductNo');
            $table->string('SalePrice'); // Storing price as string as requested
            $table->timestamps();

            // ✅ Foreign key constraints (assuming referenced columns are also strings)
            $table->foreign('CustomerNo')
                ->references('CustomerNo')
                ->on('customers')
                ->onDelete('cascade');

            $table->foreign('ProductNo')
                ->references('ProductCode')
                ->on('products')
                ->onDelete('cascade');

            // Optional: enforce uniqueness of CustomerNo + ProductNo pair
            // $table->unique(['CustomerNo', 'ProductNo']);
        });
    }

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