<?php

namespace ModulesGarden\HostingQuotaNotifications\App\Helper\SmartyHelper;

use \ModulesGarden\HostingQuotaNotifications\Core\Models\Whmcs\Order as OrderWHMCS;

/**
 * Description of Order
 *
 * @author Artur Pilch <artur.pi@modulesgarden.com>
 */
class Order
{
    private $data;
    private $output;

    public function __construct($id)
    {
        $order      = OrderWHMCS::where('id', $id)->get();
        $order      = $order->toArray();
        $this->data = reset($order);
    }

    public function getFormatedData()
    {
        $this->output = $this->data;
        return $this->output;
    }

    public function getMergeFields()
    {
        $map      = self::getMergeFieldsMap();
        $formated = $this->getFormatedData();
        $fields   = array();

        foreach ($map as $k => $v)
            $fields[$k] = $formated[$v];

        return $fields;
    }

    public static function getMergeFieldsNames()
    {
        return array_keys(self::getMergeFieldsMap());
    }

    private static function getMergeFieldsMap()
    {
        return [
            'order_id'             => 'id',
            'order_number'         => 'ordernum',
            'order_date'           => 'date',
            'order_payment_method' => 'paymentmethod',
            'invoice_id'           => 'invoiceid',
            'order_notes'          => 'notes',
            'order_user'           => 'userid',
            'order_nameservers'    => 'nameservers',
            'order_amount'         => 'amount',
            'client_ip'            => 'ipaddress'
            ];
    }
}
