<?php

namespace ModulesGarden\Servers\ZimbraEmail\App\Http\Client;

use ModulesGarden\Servers\ZimbraEmail\App\Enums\ControllerEnums;
use ModulesGarden\Servers\ZimbraEmail\App\Enums\ProductParams;
use ModulesGarden\Servers\ZimbraEmail\App\Helpers\BuildUrlExtended;
use ModulesGarden\Servers\ZimbraEmail\App\Libs\Product\ProductManager;
use ModulesGarden\Servers\ZimbraEmail\App\UI\Admin\Custom\Pages\Description;
use ModulesGarden\Servers\ZimbraEmail\App\UI\Client\DistributionList\Pages\Lists;
use ModulesGarden\Servers\ZimbraEmail\App\UI\Client\EmailAccount\Pages\Accounts;
use ModulesGarden\Servers\ZimbraEmail\Core\Helper;
use ModulesGarden\Servers\ZimbraEmail\Core\Http\AbstractClientController;
use ModulesGarden\Servers\ZimbraEmail\Core\UI\Traits\WhmcsParams;

/**
 *
 * Created by PhpStorm.
 * User: Tomasz Bielecki ( tomasz.bi@modulesgarden.com )
 * Date: 10.09.19
 * Time: 10:12
 * Class DistributionList
 */
class DistributionList extends AbstractClientController
{
    use WhmcsParams;

    public function index()
    {
        $productManager = new ProductManager();
        $productManager->loadByHostingId($this->request->get('id'));
        if ($this->getWhmcsParamByKey('status') !== 'Active' || !$productManager->isControllerAccessible(ControllerEnums::DISTRIBUTION_MAIL_PAGE))
        {
            return Helper\redirectByUrl(BuildUrlExtended::getProvisioningUrl('',false,false));
        }

        return Helper\view()
            ->addElement(new Description('distributionList'))
            ->addElement(Lists::class)
            ;
    }
}