<?php

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

return new class extends Migration
{
    /**
     * The per-tenant entitlement ceiling: which permissions (module.action) a
     * tenant may use at all. Set by the landlord in master control. A tenant's
     * own roles/users can never grant beyond this set.
     */
    public function up(): void
    {
        Schema::create('tenant_permissions', function (Blueprint $table) {
            $table->id();
            $table->foreignId('tenant_id')->constrained('tenants')->cascadeOnDelete();
            $table->foreignId('permission_id')->constrained('permissions')->cascadeOnDelete();
            $table->timestamps();

            $table->unique(['tenant_id', 'permission_id']);
        });
    }

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