<?php
declare(strict_types=1);

namespace Autogedal\StockLog\Model;

/**
 * Singleton that carries the "who is changing stock right now" context.
 * Each cron/process calls setSource() at the start of its execute().
 * The plugin and observer read getSource() when writing a log entry.
 */
class StockSourceContext
{
    private static ?self $instance = null;
    private string $source = 'unknown';

    private function __construct() {}

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

    public function setSource(string $source): void
    {
        $this->source = $source;
    }

    public function getSource(): string
    {
        return $this->source;
    }

    public function reset(): void
    {
        $this->source = 'unknown';
    }
}
