<?php

namespace ModulesGarden\Servers\OpenXchange\App\Http\Actions;

use ModulesGarden\Servers\OpenXchange\App\Libs\RestApi;
use ModulesGarden\Servers\OpenXchange\Core\App\Controllers\Instances\AddonController;

/**
 *
 * Created by PhpStorm.
 * User: Tomasz Bielecki ( tomasz.bi@modulesgarden.com )
 * Date: 09.09.19
 * Time: 15:14
 * Class SuspendAccount
 */
class SuspendAccount extends AddonController
{

    /**
     * create domain in zimbra
     *
     * @param null $params
     * @return string
     */
    public function execute($params = null)
    {
        try
        {
            $context = new RestApi($params);
            $users   = $context->listAllUsers();
            
            foreach ($users as $user)
            {
                $context->suspendUser($user->name);
            }
        }
        catch (\Exception $ex)
        {
            /**
             * return some crit error
             */
            return $ex->getMessage();
        }

        return 'success';
    }
}
