<?php
/**
 *
 * User: Artur Pilch <artur.pi@modulesgarden.com>
 * Date: 2018-08-06
 * Time: 14:22
 */

namespace ModulesGarden\HostingQuotaNotifications\App\Helper\Notifications;

use ModulesGarden\HostingQuotaNotifications\App\Helper\SmartyHelper\Product;
use ModulesGarden\HostingQuotaNotifications\App\Helper\SmartyHelper\Client;
use ModulesGarden\HostingQuotaNotifications\App\Helper\SmartyHelper\Other;
use ModulesGarden\HostingQuotaNotifications\App\Helper\SmartyHelper\Notification;
use ModulesGarden\HostingQuotaNotifications\App\Helper\Lang\Lang;
use ModulesGarden\HostingQuotaNotifications\App\Helper\Basics\Converter;
use ModulesGarden\HostingQuotaNotifications\App\Helper\SmartyHelper\SmartyHelper;
use ModulesGarden\HostingQuotaNotifications\App\Helper\Models\Hosting;

class OpenTicket
{
    public static function assignValues($message, $data)
    {
        $smarty = new SmartyHelper();

        $hostingId = $data['hostingId'];
        $userId    = Hosting::getValueById($hostingId, 'userid');

        $data += Hosting::getServiceLimits($hostingId);

        $smartyValues = self::getValuesToAssign($hostingId, $userId, $data);

        $out = [];
        foreach ($smartyValues as $values)
        {
            $out = array_merge($out, $values);
        }
        return $smarty->assignVariables($message, $out);
    }

    public static function getValuesToAssign($hostingId, $userId, $data)
    {
        return [
            'product'      => (new Product($hostingId))->getMergeFields(),
            'client'       => (new Client($userId))->getMergeFields(),
            'other'        => (new Other())->getMergeFields(),
            'notification' => (new Notification(self::getNotificationsValuesToAssign($data)))->getMergeFields()
        ];
    }

    public static function getNotificationsValuesToAssign($data)
    {
        return [
            'notification_limit'                   => $data['value'],
            'notification_usage'                   => $data['usage'],
            'notification_kind'                    => Lang::getAbsoulteLang('kind', $data['kind']),
            'notification_differenceUsageAndLimit' => $data['differenceUsageAndLimit'],
            'notification_periodDays'              => $data['countedDays'],
            'notification_unit'                    => $data['unit'],
            'service_bwLimit'                      => $data['serviceBwLimit'],
            'service_diskLimit'                    => $data['serviceDiskLimit'],
        ];
    }
}