<?php

namespace App\Libraries;

/**
 * Request-scoped singleton that carries the resolved church_id and user
 * so models and controllers can access them without re-querying.
 */
class ChurchContext
{
    private static ?self $instance = null;

    private ?int   $churchId        = null;
    private ?array $user            = null;
    private bool   $isPlatformAdmin = false;
    private ?array $platformAdmin   = null;

    public static function getInstance(): self
    {
        if (self::$instance === null) {
            self::$instance = new self();
        }
        return self::$instance;
    }

    public function setChurchId(int $id): void       { $this->churchId = $id; }
    public function getChurchId(): ?int               { return $this->churchId; }

    public function setUser(array $user): void        { $this->user = $user; }
    public function getUser(): ?array                 { return $this->user; }

    public function setIsPlatformAdmin(bool $v): void { $this->isPlatformAdmin = $v; }
    public function isPlatformAdmin(): bool           { return $this->isPlatformAdmin; }

    public function setPlatformAdmin(array $a): void  { $this->platformAdmin = $a; }
    public function getPlatformAdmin(): ?array        { return $this->platformAdmin; }
}
