<?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
    {
        // Per-project VISIBILITY grant (Team Workspaces P3d / Δ23). NO role
        // column — capability comes from the workspace `tenant_user.role`; this
        // pivot is pure visibility (which non-owner/non-admin member can SEE
        // which project). Owner/admin see all via short-circuit, so they get no
        // rows. SaaS-only — self-hosted writes none (single all-see-all pool).
        Schema::create('project_user', function (Blueprint $table) {
            $table->id();
            $table->foreignId('project_id')->constrained('projects')->cascadeOnDelete();
            $table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
            $table->timestamps();

            $table->unique(['project_id', 'user_id']);
            $table->index('user_id');
        });
    }

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