<?php

namespace ModulesGarden\Servers\OpenXchange\App\UI\Client\EmailCatchAll\Providers;


//use ModulesGarden\Servers\OpenXchange\App\Libs\OXUser;
//use ModulesGarden\Servers\OpenXchange\App\Libs\OXService;
use ModulesGarden\Servers\OpenXchange\App\Libs\RestApi;
use ModulesGarden\Servers\OpenXchange\App\Helpers\Helper;
use ModulesGarden\Servers\OpenXchange\App\Helpers\ZimbraManager;
use ModulesGarden\Servers\OpenXchange\Core\Models\Whmcs\Hosting;
use ModulesGarden\Servers\OpenXchange\App\Libs\Product\ProductManager;
use ModulesGarden\Servers\OpenXchange\Core\UI\ResponseTemplates\HtmlDataJsonResponse;
use ModulesGarden\Servers\OpenXchange\Core\UI\Widget\Forms\DataProviders\BaseDataProvider;
use ModulesGarden\Servers\OpenXchange\App\Libs\Zimbra\Components\Api\Soap\Models\AccountAlias;

/**
 *
 * Created by PhpStorm.
 * User: Tomasz Bielecki ( tomasz.bi@modulesgarden.com )
 * Date: 18.09.19
 * Time: 12:59
 * Class DeleteEmailCatchAllDataProvider
 */
class DeleteEmailCatchAllDataProvider extends BaseDataProvider
{

    public function read()
    {
        $params           = json_decode(base64_decode($this->actionElementId), true);
        $this->data['id'] = $params['username'];
    }

    public function update()
    {

    }

    public function delete()
    {
        try
        {
            $hid    = $this->getRequestValue('id');
            $params = Helper::moduleParams($hid);

            $context = new RestApi($params);
            $result  = $context->deleteDomainCatchall($this->formData['id']);

            return (new HtmlDataJsonResponse())->setMessageAndTranslate('EmailCatchAllHasBeenDeleted')->setStatusSuccess();

        }
        catch(\Exception $e)
        {
            return (new HtmlDataJsonResponse())->setMessageAndTranslate('CannotDeleteDomainCatchAll')->setStatusError();
        }
    }
}