<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace ModulesGarden\HostingQuotaNotifications\App\Libs\Cron\Notifications\Types;

use ModulesGarden\HostingQuotaNotifications\App\Libs\Cron\Notifications\Actions;
use ModulesGarden\HostingQuotaNotifications\App\Libs\Cron\Notifications\Queries\Fixed as QueriesFixed;
use ModulesGarden\HostingQuotaNotifications\App\Libs\Groups\Constants as GroupConstants;
use ModulesGarden\HostingQuotaNotifications\App\Helper\Notifications\StepsConfiguration;
use ModulesGarden\HostingQuotaNotifications\App\Libs\Cron\Notifications\Types\Interfaces\TypeMessages;
use ModulesGarden\HostingQuotaNotifications\App\Helper\Basics\Unit;

/**
 * Description of Fixed
 *
 * @author Artur Pilch <artur.pi@modulesgarden.com>
 */
class Fixed implements TypeMessages
{
    public function getMessagesIfDeclaredLimitIsReached($configuration, $products)
    {
        $out = [];
        foreach ($configuration as $kind => $conf)
        {
            $out[$kind] = $this->getMessages($conf, $kind, $products);
        }
        return $out;
    }

    private function getMessages($configuration, $kind, $products)
    {
        foreach ($configuration as $conf)
        {
            $conf['value'] = Unit::calculateByUnit($conf['unit'], $conf['value']);
            $query         = QueriesFixed::checkForMessages($conf, $products, $kind);

            if ($query)
            {
                return $query;
            }
        }
        return null;
    }
}
