<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
 * Per-project visibility grant (Team Workspaces P3d / Δ23) — the `project_user`
 * pivot. A row means the granted user can SEE the project; capability (edit vs
 * read-only) still comes from the workspace `tenant_user.role`. No role column.
 *
 * Owner/admin see every workspace project via short-circuit (no rows). Grants
 * are created when an owner/admin shares a project, and auto-created when a
 * plain editor creates one (store / duplicate / kit-install). Cascade-deletes
 * on project delete OR workspace-member removal (both FKs cascadeOnDelete).
 *
 * SaaS-only — self-hosted writes no rows (single all-see-all pool).
 */
#[Fillable(['project_id', 'user_id'])]
class ProjectMember extends Model
{
    protected $table = 'project_user';

    public function project(): BelongsTo
    {
        return $this->belongsTo(Project::class);
    }

    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }
}
