<?php

namespace CouponsPlus\App\Offers;

use CouponsPlus\Original\Collections\Collection;

class HardLimits
{
    /**
     * I hate this pattern, but until we port this to our newest framework that supports dependency injection,
     * this will have to do.
     */
    protected static ?self $instance = null;

    /**
     * a key-pair collection of hard limits
     * where the key is the unique id of the offer and the value is a HardLimit object
     */
    protected Collection $limits;
    public static function getInstance(): self
    {
        if (!isset(self::$instance)) {
            self::$instance = new self();
        }

        return self::$instance;
    }

    protected function __construct()
    {
        $this->limits = new Collection([]);
    }

    public function register(string $offerId, float $hardLimitAmount) : HardLimit
    {
        $hardLimit = new HardLimit($offerId, $hardLimitAmount);

        $this->limits->set($offerId, $hardLimit);

        return $hardLimit;
    }

    public function get(string $offerId) : ?HardLimit
    {
        return $this->limits->get($offerId);
    }
}