<?php
/**
 *
 * User: Artur Pilch <artur.pi@modulesgarden.com>
 * Date: 2018-07-31
 * Time: 14:50
 */

namespace ModulesGarden\HostingQuotaNotifications\App\Helper\Logger;


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

class SendMail
{
    CONST SEND_EMAIL =  'SendEmail';

    public static function format($row, $key)
    {
        $data = [
            'lang'      => Lang::getAbsoulteLang('logs', 'product'),
            'user'      => Hosting::getValueById($row['vars']['hostingId'], 'userid'),
            'hostingId' => $row['vars']['hostingId'],
            'message'   => $row['response']['message'],

            'kind'      => $row['vars']['kind'],
        ];

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

    public static function error($data)
    {
        $lang = Lang::getAbsoulteLang('logs', 'sendMailError');
        $url  = sprintf(Hosting::URL, $data['user'], $data['hostingId'], $data['lang'], $data['hostingId']);
        return $lang . ': ' . $data['message'] . '. ' . $url;

    }

    public static function success($data)
    {
        $lang = Lang::getAbsoulteLang('logs', 'sendMailSuccess');
        $lang = sprintf($lang, Converter::kind($data['kind']));
        $url  = sprintf(Hosting::URL, $data['user'], $data['hostingId'], $data['lang'], $data['hostingId']);
        return $lang . $url;
    }
}