<?php

namespace App\Support;

use App\Models\Hotel;

/**
 * Holds the hotel (tenant) the current request is operating on.
 * When set, all models using BelongsToHotel are automatically scoped
 * to it and new records are stamped with its id.
 */
class Tenancy
{
    protected static ?Hotel $hotel = null;

    public static function set(?Hotel $hotel): void
    {
        static::$hotel = $hotel;
    }

    public static function get(): ?Hotel
    {
        return static::$hotel;
    }

    public static function id(): ?int
    {
        return static::$hotel?->id;
    }

    public static function check(): bool
    {
        return static::$hotel !== null;
    }
}
