<?php

use system\library\feedback\gupshop\MessageGupshopApi;
use system\library\feedback\gupshop\MessageGupshopText;

class WhatsappNewAccount extends Whatsapp
{

    public function __construct($registry)
    {
        parent::__construct($registry);
    }

    public function sendWhats($typewhats, $customer_id, $attribute_value)
    {
        $message = $this->getMessage($this->config->get('feedback_account'), Type_FeedbackAccount::Tp_NewAccount);

        if($message){
            $this->getCustomer($customer_id);
            $attribute_value = json_decode($attribute_value, true);

            $gupshopApi = new MessageGupshopApi();
            $gupshopApi->setDestination($attribute_value['feedback_whatsapp_number']);
            $gupshopText = new MessageGupshopText();
            $gupshopText->setIsHSM('true');
            $gupshopText->setType(Type_FeedbackMessage::Tp_Text);
            $gupshopText->setText($this->ftrgeralregistry->formatMessageVariable($message, $this->getValuesVariable(), Type_LayoutPersonalizadoVarButton::getEnumList()));
            $gupshopApi->setMessage($gupshopText);


            $result = $this->feedback->sendMessages($this->feedback->getIntegrationEnabled(), $gupshopApi);
            if($result){
                if(property_exists($result, 'type') && ($result->type == 'error')){
                    throw new Exception($result->message);
                }
            }
        }
    }

}