<?php

class ControllerMarketplaceMktJobs extends Controller
{

  private $marketplaces = array();

  public function __construct($registry)
  {
    parent::__construct($registry);
    $this->load->dmodel('setting/task');
    $this->load->type('tipocomum');

    $this->marketplaces = array_filter(array(
      Type_MarketPlace::Tp_Mercadolivre => $this->config->get('mercadolivre_status'),
      Type_MarketPlace::Tp_SkyHub => $this->config->get('skyhub_status'),
      Type_MarketPlace::Tp_Galeriapage => $this->config->get('galeriapage_status'),
      Type_MarketPlace::Tp_Shopee => $this->config->get('shopee_status'),
    ));

  }

  public function atualizarPedidos()
  {

  }

  public function notificarStatusOrders()
  {

  }

  public function mktQuestions()
  {

    $ctrMkt = array();
    $count = 0;
    do{

      foreach ($this->marketplaces as $key => $marketplace) {

        $directory = strtolower(Type_MarketPlace::getNickFromValue($key));
        $path = strtolower(Type_MarketPlace::getNickFromValue($key));
        $controllerLoad = 'controller_' . $directory . '_' . $path;

        if(!$this->registry->has($controllerLoad)){
          $this->load->controllerRegistry($directory . '/' . $path);
        }

        if ($this->hasAction($directory . '/' . $path . '/getQuestion')) {
          $ctrMkt[$key] = $this->{$controllerLoad}->getQuestion($count);
          if(!$ctrMkt[$key]){
            unset($this->marketplaces[$key]);
          }
        }

        $count++;

      }

    }while(count(array_filter($ctrMkt)) > 0);


  }

}