<?php

namespace ThurData\Servers\KerioEmail\App\Http\Client;

use ThurData\Servers\KerioEmail\App\Enums\ControllerEnums;
use ThurData\Servers\KerioEmail\App\Enums\ProductParams;
use ThurData\Servers\KerioEmail\App\Helpers\BuildUrlExtended;
use ThurData\Servers\KerioEmail\App\Libs\Product\ProductManager;
use ThurData\Servers\KerioEmail\App\UI\Admin\Custom\Pages\Description;
use ThurData\Servers\KerioEmail\App\UI\Client\DomainAlias\Pages\DomainAliases;
use ThurData\Servers\KerioEmail\App\UI\Client\EmailAccount\Pages\Accounts;
use ThurData\Servers\KerioEmail\Core\Http\AbstractClientController;
use ThurData\Servers\KerioEmail\Core\UI\Traits\WhmcsParams;
use ThurData\Servers\KerioEmail\Core\Helper;

/**
 *
 * Created by PhpStorm.
 * User: ThurData
 * Date: 10.09.19
 * Time: 10:13
 * Class DomainAlias
 */
class DomainAlias extends AbstractClientController
{
    use WhmcsParams;

    public function index()
    {
        $productManager = new ProductManager();
        $productManager->loadByHostingId($this->request->get('id'));

        if ($this->getWhmcsParamByKey('status') !== 'Active' ||
            $productManager->get(ControllerEnums::DOMAIN_ALIAS_PAGE) !== ProductParams::SWITCHER_ENABLED)
        {
            return Helper\redirectByUrl(BuildUrlExtended::getProvisioningUrl('',false,false));
        }

        return Helper\view()
            ->addElement(new Description('domainAlias'))
            ->addElement(DomainAliases::class)
            ;

    }
}