<?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\Models;

use \ModulesGarden\HostingQuotaNotifications\Core\Models\Whmcs\EmailTemplate as EmailTemplatesModel;
use \ModulesGarden\HostingQuotaNotifications\Core\Models\Whmcs;
use \ModulesGarden\HostingQuotaNotifications\App\Helper\Constants\Functions;

/**
 * Description of EmailTemplates
 *
 * @author Artur Pilch <artur.pi@modulesgarden.com>
 */
class EmailTemplates
{
    public static function getValueById($id, $value)
    {
        return EmailTemplatesModel::where('id', '=', $id)->value($value);
    }

    
    public static function getEmailTemplates()
    {
        return Whmcs\EmailTemplate::where('type', '=', 'product')->orderBy('name')->get();
    }

    public static function getEmailTemplatesIdAsKeyAndNameAsValue($onlyTemplates = false, $default = false)
    {
        $out = $onlyTemplates ? [] : Functions::addNone($default);
        return $out + self::getEmailTemplates()->pluck('name', 'id')->toArray();
    }

    public static function getTemplateIdFromName($name)
    {
        $exist =  EmailTemplatesModel::where('name', '=', $name)->get()->first();
        return $exist ? $exist->id : Functions::NONE;
    }
}
