<?php

class NotificacaoMarketplaceStatus extends Pedido
{

  private $registry;
  private $db;

  public function __construct($registry)
  {
    $this->registry = $registry;
    $this->db = $registry->get('db');
    parent::__construct($registry);
  }
  public function __get($name) {
    return $this->registry->get($name);
  }

  public function sendTask($typeemail, $order_id, $attribute_value)
  {
    try {
      $this->load->dmodel('marketplace/mktpedido');
      $attribute_value = json_decode($attribute_value);

      switch ($attribute_value->mkt_integracao_tipo){
          case Type_MarketPlace::Tp_Mercadolivre:

              $data = array(
                  'order_id'         => $order_id,
                  'get_nfe_server'   => true,
                  'order_history_id' => $attribute_value->order_history_id
              );

              $this->load->dmodel('mercadolivre/melipedido');
              return $this->dmodel_mercadolivre_melipedido->sendNfesML($data);
              break;
          case Type_MarketPlace::Tp_SkyHub:
              $this->load->dmodel('skyhub/skypedido');
              return $this->dmodel_skyhub_skypedido->sendStatus($order_id, $attribute_value->order_status_id, $attribute_value->order_history_id);
              break;
          case Type_MarketPlace::Tp_Galeriapage:
              $this->load->dmodel('galeriapage/gppedido');
              return $this->dmodel_galeriapage_gppedido->sendStatus($order_id, $attribute_value->order_status_id, $attribute_value->order_history_id);
              break;
          case Type_MarketPlace::Tp_Shopee:
              $this->load->dmodel('shopee/shopeepedido');
              return $this->dmodel_shopee_shopeepedido->sendStatus($order_id, $attribute_value->order_status_id, $attribute_value->order_history_id);
              break;
      }

    } catch (Exception $e) {
      throw $e;
    }
  }



}