<?php

namespace App\Support;

use App\Models\Tenant;

/**
 * Request-scoped container for the resolved tenant.
 * Bound as a singleton; set once by ResolveTenant middleware.
 */
class Tenancy
{
    protected ?Tenant $tenant = null;

    public function set(Tenant $tenant): void
    {
        $this->tenant = $tenant;
    }

    public function get(): ?Tenant
    {
        return $this->tenant;
    }

    public function id(): ?int
    {
        return $this->tenant?->id;
    }

    public function check(): bool
    {
        return $this->tenant !== null;
    }

    public function forget(): void
    {
        $this->tenant = null;
    }
}
