<?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('Perusahaan_User', function (Blueprint $table) {
            // Perusahaan.PerusahaanID was created with $table->id(), so it's bigint
            $table->unsignedBigInteger('PerusahaanID');
            // users.id is UUID in this project
            $table->uuid('UserID');
            $table->timestamps();

            $table->primary(['PerusahaanID', 'UserID']);

            // Foreign key constraints
            $table->foreign('PerusahaanID')->references('PerusahaanID')->on('Perusahaan')->onDelete('cascade');
            $table->foreign('UserID')->references('id')->on('users')->onDelete('cascade');
        });
    }

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