<?php
/*
 * 888888ba                 dP  .88888.                    dP
 * 88    `8b                88 d8'   `88                   88
 * 88aaaa8P' .d8888b. .d888b88 88        .d8888b. .d8888b. 88  .dP  .d8888b.
 * 88   `8b. 88ooood8 88'  `88 88   YP88 88ooood8 88'  `"" 88888"   88'  `88
 * 88     88 88.  ... 88.  .88 Y8.   .88 88.  ... 88.  ... 88  `8b. 88.  .88
 * dP     dP `88888P' `88888P8  `88888'  `88888P' `88888P' dP   `YP `88888P'
 *
 *                          m a g n a l i s t e r
 *                                      boost your Online-Shop
 *
 * -----------------------------------------------------------------------------
 * (c) 2010 - 2023 RedGecko GmbH -- http://www.redgecko.de
 *     Released under the MIT License (Expat)
 * -----------------------------------------------------------------------------
 */

class ML_PriceMinister_Model_Modul extends ML_Modul_Model_Modul_Abstract {

    /**
     * @var ML_Shop_Model_Price_Interface $oPrice
     */
    protected $oPrice = null;

    public function getMarketPlaceName($blIntern = true) {
        return $blIntern ? 'priceminister' : MLI18n::gi()->get('sModuleNamePriceMinister');
    }

    public function getOrderLogo(ML_Shop_Model_Order_Abstract $oOrder) {
        return 'priceminister_orderview.png';
    }

    public function getConfig($sName = null) {
        if ($sName == 'currency') {
            $mReturn = 'EUR';
        } else {
            $mReturn = parent::getConfig($sName);
        }

        if ($sName === null) {// merge
            $mReturn = MLHelper::getArrayInstance()->mergeDistinct($mReturn, array(
                'lang' => parent::getConfig('lang'),
                'currency' => 'EUR'
            ));
        }

        return $mReturn;
    }

    public function getStatusConfigurationKeyToBeConfirmedOrCanceled() {
        $configFields = parent::getStatusConfigurationKeyToBeConfirmedOrCanceled();
        $configFields = array_merge(['orderstatus.accepted', 'orderstatus.refused', 'orderstatus.shipped'],$configFields);

        return $configFields;
    }

    public function getStockConfig($sType = null) {
        return array(
            'type' => $this->getConfig('quantity.type'),
            'value' => $this->getConfig('quantity.value')
        );
    }

    /**
     * @return array('configKeyName'=>array('api'=>'apiKeyName', 'value'=>'currentSantizedValue'))
     */
    protected function getConfigApiKeysTranslation() {
        $aConfig = $this->getConfig();
        $sDate = $aConfig['preimport.start'];
        //magento tip to find empty date
        $sDate = (preg_replace('#[ 0:-]#', '', $sDate) === '') ? date('Y-m-d') : $sDate;
        $sDate = date('Y-m-d', strtotime($sDate));
        $sSync = $this->getConfig('stocksync.tomarketplace');
        $sOrderAcceptance = isset($aConfig['orderstatus.autoacceptance']) ? $aConfig['orderstatus.autoacceptance'] == 1 : true;
        $sOrderShippingFromCountry = isset($aConfig['orderimport.shippingfromcountry']) ? $aConfig['orderimport.shippingfromcountry'] : '';
        return array(
            'import' => array('api' => 'Orders.Import', 'value' => ($this->getConfig('import') ? 'true' : 'false')),
            'preimport.start' => array('api' => 'Orders.Import.Start', 'value' => $sDate),
            'stocksync.tomarketplace' => array('api' => 'Callback.SyncInventory', 'value' => isset($sSync) ? $sSync : 'no'),
            'orderstatus.autoacceptance' => array('api' => 'Orders.AutoAcceptance', 'value' => $sOrderAcceptance),
            'orderimport.shippingfromcountry' => array('api' => 'Orders.ShippingFromCountry', 'value' => $sOrderShippingFromCountry),
        );
    }
    public function getListOfConfigurationKeysNeedShopValidationOnlyActive() {
        return array(
            'orderimport.paymentmethod' => 'config_orderimport' ,
            'orderimport.shippingmethod'=> 'config_orderimport' ,
        );
    }

}
