<?php

class Whatsapp
{

    private $registry;
    private $customer = false;
    private $order = false;
    public $log;

    public function __construct($registry)
    {
        $this->registry = $registry;
        $this->load = $registry->get('load');
        $this->language = $registry->get('language');
        $this->config = $registry->get('config');
        $this->url = $registry->get('url');
        $this->log = new BaseLog($registry);
    }

    public function __get($name)
    {
        return $this->registry->get($name);
    }

    protected function getCustomer($customer_id)
    {
        $this->load->dmodel('account/customer');
        $this->customer = $this->dmodel_account_customer->getCustomer($customer_id);
    }

    protected function getOrder($order_id)
    {
        $this->load->model('account/order');
        $this->order = $this->model_account_order->getOrder($order_id);
    }

    public function getMessage($messages, $messageIndex)
    {
        return current(array_map(function($array) use(&$messageIndex){
            return ($array['id'] == $messageIndex) ? $array['message'] : false;
        }, $messages));
    }

    protected function getValuesVariable()
    {
        return array(
            Type_LayoutPersonalizadoVarButton::Tp_Clinome      => ($this->customer) ? $this->customer['firstname'].' '.$this->customer['lastname'] : false,
            Type_LayoutPersonalizadoVarButton::Tp_Cliemail     => ($this->customer) ? $this->customer['email'] : false,
            Type_LayoutPersonalizadoVarButton::Tp_Lojnome      => $this->config->get('config_name'),
            Type_LayoutPersonalizadoVarButton::Tp_Lojlink      => $this->url->link('common/home', '', 'SSL'),
            Type_LayoutPersonalizadoVarButton::Tp_Lojloginlink => $this->url->link('account/register', '', 'SSL'),
            Type_LayoutPersonalizadoVarButton::Tp_PedidoID     => ($this->order) ? $this->order['order_id'] : false
        );
    }


}