<?php
/**
 * Created by PhpStorm.
 * User: devweb
 * Date: 15/02/21
 * Time: 15:37
 */

final class Feedback
{

    public $registry;
    private $config;
    private $user;
    private $load;

    public $logArray;
    private $integrations;

    public function __construct($registry)
    {
        $this->registry = $registry;
        $this->config = $registry->get('config');
        $this->user = $registry->get('user');
        $this->load = $registry->get('load');
        $this->integrations[Type_Integration::Tp_Gupshop] = new Gupshop($this->registry);
    }

    public function isEnabled()
    {
        if ($this->config->get('feedback_automatico_status')) {

            foreach (Type_Integration::getEnumList() as $key => $integration) {
                $integration = strtolower($integration);
                if ($this->config->get($integration . '_status')) {
                    return true;
                }
            }

        } else {
            return false;
        }
    }

    public function getIntegrationEnabled()
    {
        if ($this->config->get('feedback_automatico_status')) {

            foreach (Type_Integration::getEnumList() as $key => $integration) {
                $integration = strtolower($integration);
                if ($this->config->get($integration . '_status')) {
                    return $key;
                }
            }

        } else {
            return false;
        }
    }

    public function sendMessages($integration, $data, $log = false)
    {
        try {
            return $this->integrations[$integration]->sendMessages($data, $log);
        } catch (Exception $e) {
            throw new Exception($this->marketplaces[$integration]->setErrors($e->getMessage()));
        }
    }

    public function sendMessagesAutomatic($integration, $data, $log = false)
    {
        try {
            return $this->integrations[$integration]->sendMessagesAutomatic($data, $log);
        } catch (Exception $e) {
            throw new Exception($this->marketplaces[$integration]->setErrors($e->getMessage()));
        }
    }

    public function getUrlCallback($integration, $data, $log = false)
    {
        try {
            return $this->integrations[$integration]->getUrlCallback($data, $log);
        } catch (Exception $e) {
            throw new Exception($this->marketplaces[$integration]->setErrors($e->getMessage()));
        }
    }


}