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

namespace ModulesGarden\HostingQuotaNotifications\App\Helper\Logger;


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

class OpenTicket
{
    CONST OPEN_TICKET = 'OpenTicket';
    CONST NO_LANG = 'NoLangToOpenTicket';

    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)
    {
        $message = $row['response']['message'];
        if ($row['message'] == SELF::NO_LANG)
        {
            $message = Lang::getAbsoulteLang('logs', $row['message']);
        }
        $lang = Lang::getAbsoulteLang('logs', 'openTicketError');
        return $lang . ': ' . $message;

    }

    public static function success($row)
    {
        $lang     = Lang::getAbsoulteLang('logs', 'openTicketSuccess');
        $ticketId = $row['response']['id'];
        $url      = sprintf(Ticket::URL, $ticketId, Lang::getAbsoulteLang('logs', 'ticket'), $ticketId);
        return $lang . $url;
    }
}