<?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\Helper\Logger;

use ModulesGarden\HostingQuotaNotifications\App\Helper\Constants\Status;
use \ModulesGarden\HostingQuotaNotifications\App\Helper\Models\Hosting;
use ModulesGarden\HostingQuotaNotifications\App\Helper\Lang\Lang;

/**
 * Description of ModuleAction
 *
 * @author Artur Pilch <artur.pi@modulesgarden.com>
 */
class ModuleAction
{
    CONST MODULE_TERMINATE = 'ModuleTerminate';
    CONST MODULE_SUSPEND = 'ModuleSuspend';
    CONST MODULE = 'Module';

    public static function format($row, $key)
    {

        if ($row['type'] == Status::SUCCESS)
        {
            return html_entity_decode(self::success($row));
        }
        return html_entity_decode(self::error($row));
    }

    public static function error($row)
    {
        $lang      = Lang::getAbsoulteLang('logs', 'product');
        $hostingId = $row['request']['accountid'];
        $user      = Hosting::getValueById($hostingId, 'userid');
        $url       = sprintf(Hosting::URL, $user, $hostingId, $lang, $hostingId);

        if($row['response']['message'])
        {
            $reason = Lang::getAbsoulteLang('log', 'reason');
            $response = ' ('.$reason.': ' .$row['response']['message'] .')';
        }

        return $url . ' ' . Lang::getAbsoulteLang('log', $row['message'].'Error') . $response;
    }

    public static function success($row)
    {
        $lang      = Lang::getAbsoulteLang('logs', 'product');
        $hostingId = $row['request']['accountid'];
        $user      = Hosting::getValueById($hostingId, 'userid');
        $url       = sprintf(Hosting::URL, $user, $hostingId, $lang, $hostingId);

        return $url . ' ' . Lang::getAbsoulteLang('log', $row['message'].'Success');
    }
}
