<?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('dsg_pay_map', function (Blueprint $table) {

            $table->bigIncrements('DPM_Id');

            $table->unsignedBigInteger('Dsg_id');
            $table->unsignedBigInteger('PC_id')->nullable();
            $table->unsignedBigInteger('PST_id')->nullable();
            $table->unsignedBigInteger('PS_id')->nullable();
            $table->unsignedBigInteger('PB_id')->nullable();
            $table->unsignedBigInteger('PGM_id')->nullable();
            $table->unsignedBigInteger('PL_Id')->nullable();

            $table->timestamps();
            $table->softDeletes();

            // ✅ FK 1
            $table->foreign('Dsg_id', 'fk_ds_p')
                ->references('Dsg_id')
                ->on('designation_master')
                ->cascadeOnUpdate()
                ->restrictOnDelete();

            // ✅ FK 2
            $table->foreign('PC_id', 'fk_dsg_p')
                ->references('PC_Id')
                ->on('pay_comm_master')
                ->cascadeOnUpdate()
                ->restrictOnDelete();

            // ✅ FK 3
            $table->foreign('PST_id', 'fk_dsg_pa')
                ->references('PST_Id')
                ->on('pay_strtype_master')
                ->cascadeOnUpdate()
                ->restrictOnDelete();

            // ✅ FK 4
            $table->foreign('PS_id', 'fk_dsg_pay')
                ->references('PS_Id')
                ->on('pay_scale_master')
                ->cascadeOnUpdate()
                ->restrictOnDelete();

            // ✅ FK 5
            $table->foreign('PB_id', 'fk_dsgg_pay')
                ->references('PB_Id')
                ->on('pay_band_master')
                ->cascadeOnUpdate()
                ->restrictOnDelete();

            // ✅ FK 6
            $table->foreign('PGM_id')
                ->references('PGM_Id')
                ->on('pay_grade_master')
                ->cascadeOnUpdate()
                ->restrictOnDelete();

            // ✅ FK 7
            $table->foreign('PL_Id')
                ->references('PL_Id')
                ->on('pay_level_master')
                ->cascadeOnUpdate()
                ->restrictOnDelete();
        });
    }

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