<?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('company_profile_company_specialisations', function (Blueprint $table) {
            $table->unsignedBigInteger('company_profile_id');
            $table->unsignedBigInteger('company_specialisation_id');
            $table->unsignedInteger('position')->nullable();

            $table->primary(
                ['company_profile_id', 'company_specialisation_id'],
                'company_profile_company_specialisations_pk'
            );

            $table->foreign('company_profile_id', 'cp_specialisations_profile_fk')
                ->references('id')
                ->on('company_profiles')
                ->onDelete('CASCADE')
                ->onUpdate('CASCADE');

            $table->foreign('company_specialisation_id', 'cp_specialisations_specialisation_fk')
                ->references('id')
                ->on('company_specialisations')
                ->onDelete('CASCADE')
                ->onUpdate('CASCADE');
        });
    }

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