<?php

namespace ThurData\Servers\KerioEmail\Core\App\Controllers\Instances\Addon;

use ThurData\Servers\KerioEmail\Core\App\Controllers\Interfaces\AddonController;
use ThurData\Servers\KerioEmail\Core\ServiceLocator;

/**
 * Deactivate module action
 */
class Deactivate extends \ThurData\Servers\KerioEmail\Core\App\Controllers\Instances\AddonController implements AddonController
{

    /**
     * @param array $params
     * @return array
     */
    public function execute($params = [])
    {
        try
        {
            // before
            $return = ServiceLocator::call(\ThurData\Servers\KerioEmail\Core\Configuration\Addon\Deactivate\Before::class)->execute($params);

            if (!isset($return['status']))
            {
                $return['status'] = 'success';
            }

            // after
            $return = ServiceLocator::call(\ThurData\Servers\KerioEmail\Core\Configuration\Addon\Deactivate\After::class)->execute($return);

            return $return;
        }
        catch (\Exception $exc)
        {
            ServiceLocator::call(\ThurData\Servers\KerioEmail\Core\HandlerError\ErrorManager::class)->addError(self::class, $exc->getMessage(), $return);
            return [
                'status' => 'error',
                'description' => $exc->getMessage()
            ];
        }
    }
}
