<?php
/**
 * NOTICE OF LICENSE.
 *
 * Copyright 2022 Kosmonaft.dev
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 *  @author    Alexandre DEBUSSCHÈRE <alexandre@kosmonaft.dev>
 *  @copyright 2022 - 2023 Kosmonaft.dev
 *  @license   MIT
 */

if (!defined('_PS_VERSION_')) {
    exit;
}

/**
 * Trait MRMaxModuleTrait
 */
trait MRMaxModuleTrait
{

    /**
     * @return bool
     */
    protected function registerTabs()
    {
        $success = true;

        $specific = basename(__FILE__, '.php');

        // Label
        $tab = new MRMaxTab();
        $tab->class_name = 'AdminLabelsMRMax';
        $tab->module = $this->name;
        $tab->id_parent = Tab::getIdFromClassName('AdminParentOrders');
        $tab->enabled = true;
        $tab->active = true;
        $tab_name = array();
        foreach (Language::getLanguages() as $language) {
            $tab_name[$language['id_lang']] = $this->l('Mondial Relay - Labels', $specific);
        }
        $tab->name = $tab_name;

        $success &= $tab->add();

        // Tracking
        $tab = new MRMaxTab();
        $tab->class_name = 'AdminTrackingMRMax';
        $tab->module = $this->name;
        $tab->id_parent = Tab::getIdFromClassName('AdminParentOrders');
        $tab->enabled = true;
        $tab->active = true;
        $tab_name = array();
        foreach (Language::getLanguages() as $language) {
            $tab_name[$language['id_lang']] = $this->l('Mondial Relay - Tracking', $specific);
        }
        $tab->name = $tab_name;

        $success &= $tab->add();

        return $success;
    }

    /**
     * @return bool
     * @throws PrestaShopDatabaseException
     * @throws PrestaShopException
     */
    public function unregisterTabs()
    {
        $labels = new MRMaxTab(Tab::getIdFromClassName('AdminLabelsMRMax'));
        $tracking = new MRMaxTab(Tab::getIdFromClassName('AdminTrackingMRMax'));

        return $labels->delete() && $tracking->delete();
    }

    /**
     * @param array $params
     * @throws PrestaShopDatabaseException
     * @throws PrestaShopException
     * @throws SoapFault
     */
    public function hookActionValidateOrder($params)
    {
        $hook = new MRMaxHook(null, null, null, null, $this);
        $hook->actionValidateOrder($params);
    }

    /**
     * @param array $params
     * @return void
     * @throws PrestaShopDatabaseException
     * @throws PrestaShopException
     */
    public function hookActionObjectOrderUpdateAfter($params)
    {
        $hook = new MRMaxHook(null, null, null, null, $this);
        $hook->actionObjectOrderUpdateAfter($params);
    }

    /**
     * @return void
     * @throws PrestaShopDatabaseException
     * @throws PrestaShopException
     */
    public function hookDisplayHeader()
    {
        $hook = new MRMaxHook(null, null, null, null, $this);
        $hook->displayHeader();
    }

    /**
     * @param array $params
     * @return void|string
     * @throws PrestaShopDatabaseException
     * @throws PrestaShopException
     * @throws SmartyException
     */
    public function hookDisplayAdminOrder($params)
    {
        $hook = new MRMaxHook(null, null, null, null, $this);
        return $hook->displayAdminOrder($params);
    }

    /**
     * @return void
     * @throws PrestaShopDatabaseException
     * @throws PrestaShopException
     */
    public function hookDisplayBackOfficeHeader()
    {
        $hook = new MRMaxHook(null, null, null, null, $this);
        $hook->displayBackOfficeHeader();
    }

    /**
     * @return string
     * @throws PrestaShopDatabaseException
     * @throws PrestaShopException
     * @throws SmartyException
     */
    public function hookDisplayAfterBodyOpeningTag()
    {
        $hook = new MRMaxHook(null, null, null, null, $this);
        return $hook->displayAfterBodyOpeningTag();
    }

    public function hookDisplayFooter()
    {
        $hook = new MRMaxHook(null, null, null, null, $this);
        return $hook->displayFooter();
    }

    /**
     * @param array $params
     * @return string
     * @throws PrestaShopDatabaseException
     * @throws PrestaShopException
     * @throws SmartyException
     */
    public function hookDisplayCarrierExtraContent($params)
    {
        $hook = new MRMaxHook(null, null, null, null, $this);
        return $hook->displayCarrierExtraContent($params);
    }

    /**
     * @param array $params
     * @return false|string
     * @throws PrestaShopDatabaseException
     * @throws PrestaShopException
     */
    public function hookDisplayBeforeCarrier($params)
    {
        $hook = new MRMaxHook(null, null, null, null, $this);
        return $hook->displayBeforeCarrier($params);
    }

    /**
     * @param array $params
     * @return false|string
     * @throws PrestaShopDatabaseException
     * @throws PrestaShopException
     */
    public function hookDisplayOrderDetail($params)
    {
        $hook = new MRMaxHook(null, null, null, null, $this);
        return $hook->displayOrderDetail($params);
    }

    /**
     * @param array $params
     * @return void
     * @throws PrestaShopDatabaseException
     * @throws PrestaShopException
     */
    public function hookActionAdminOrdersListingFieldsModifier(&$params)
    {
        $hook = new MRMaxHook(null, null, null, null, $this);
        $hook->actionAdminOrdersListingFieldsModifier($params);
    }

    /**
     * @param array $params
     * @return void
     * @throws PrestaShopDatabaseException
     * @throws PrestaShopException
     */
    public function hookActionOrderGridDefinitionModifier(&$params)
    {
        $hook = new MRMaxHook(null, null, null, null, $this);
        $hook->actionOrderGridDefinitionModifier($params);
    }

    /**
     * @param array $params
     * @return void
     * @throws PrestaShopDatabaseException
     * @throws PrestaShopException
     */
    public function hookActionOrderGridQueryBuilderModifier(&$params)
    {
        $hook = new MRMaxHook(null, null, null, null, $this);
        $hook->actionOrderGridQueryBuilderModifier($params);
    }

    /**
     * @return bool
     * @throws PrestaShopDatabaseException
     * @throws PrestaShopException
     */
    public function hookRegisterGDPRConsent()
    {
        $hook = new MRMaxHook(null, null, null, null, $this);
        return $hook->registerGDPRConsent();
    }

    /**
     * @param array $customer
     * @return string
     * @throws PrestaShopDatabaseException
     * @throws PrestaShopException
     */
    public function hookActionDeleteGDPRCustomer($customer)
    {
        $hook = new MRMaxHook(null, null, null, null, $this);
        return $hook->actionDeleteGDPRCustomer($customer);
    }

    /**
     * @param array $customer
     * @return string
     * @throws PrestaShopDatabaseException
     * @throws PrestaShopException
     */
    public function hookActionExportGDPRData($customer)
    {
        $hook = new MRMaxHook(null, null, null, null, $this);
        return $hook->actionExportGDPRData($customer);
    }
}
