<?php


namespace ModulesGarden\Servers\ProxmoxCloudVps\App\Config\Packages;

use ModulesGarden\ProxmoxAddon\App\Services\ApiService;
use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ProductService;
use ModulesGarden\ProxmoxAddon\App\Enum\Cloud\ConfigurableOption;
use ModulesGarden\ProxmoxAddon\App\Enum\Cloud\CustomField;
use ModulesGarden\Servers\ProxmoxCloudVps\App\Libs\AwsIntegration\ClientWrapper;
use ModulesGarden\Servers\ProxmoxCloudVps\App\Models\AvailableImages\Repository;
use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Admin\ProductConfig\Providers\Config;
use ModulesGarden\Servers\ProxmoxCloudVps\Core\App\Packages\AppPackageConfiguration;
use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Traits\RequestObjectHandler;
use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Traits\WhmcsParams;
use ModulesGarden\Servers\ProxmoxCloudVps\Packages\WhmcsService\Config\Enum;

class WhmcsService extends AppPackageConfiguration
{
    use RequestObjectHandler;
    use WhmcsParams;
    use ProductService;
    use ApiService;

    const APP_CONFIGURATION =
        [
            self::PACKAGE_STATUS => self::PACKAGE_STATUS_ACTIVE,

            Enum::CUSTOM_FIELDS => [
                [
                    Enum::FIELD_NAME       => 'VLAN Tag|VLAN Tag',
                    Enum::FIELD_TYPE       => Enum::FIELD_TYPE_TEXT_BOX,
                    Enum::FIELD_ADMIN_ONLY => Enum::FIELD_ADMIN_ONLY_ON
                ],
                [
                    Enum::FIELD_NAME       => 'Authentication|Authentication',
                    Enum::FIELD_TYPE       => Enum::FIELD_TYPE_TEXT_BOX,
                    Enum::FIELD_ADMIN_ONLY => Enum::FIELD_ADMIN_ONLY_ON
                ],
                [
                    Enum::FIELD_NAME       => CustomField::ADVANCED_USER.'|Advanced User',
                    Enum::FIELD_TYPE       => Enum::FIELD_TYPE_TICK_BOX,
                    Enum::FIELD_ADMIN_ONLY => Enum::FIELD_ADMIN_ONLY_ON,
                    Enum::FIELD_RELATION_TYPE => Enum::FIELD_RELATION_TYPE_CLIENT
                ],
            ],
        ];


    public function networkRateGetSubOptions()
    {
        return [
            [
                Enum::OPTION_SUB_NAME  => "0|Unlimited",
                Enum::OPTION_SUB_ORDER => Enum::OPTION_SUB_ORDER_DEFAULT,
            ],
            [
                Enum::OPTION_SUB_NAME  => '5|5 (MB/s) (' . (5 * 8) . ' Mbps)',
                Enum::OPTION_SUB_ORDER => Enum::OPTION_SUB_ORDER_DEFAULT,
            ],
            [
                Enum::OPTION_SUB_NAME  => '10|10 (MB/s) (' . (10 * 8) . ' Mbps)',
                Enum::OPTION_SUB_ORDER => Enum::OPTION_SUB_ORDER_DEFAULT,
            ],
            [
                Enum::OPTION_SUB_NAME  => '20|20 (MB/s) (' . (20 * 8) . ' Mbps)',
                Enum::OPTION_SUB_ORDER => Enum::OPTION_SUB_ORDER_DEFAULT,
            ],
            [
                Enum::OPTION_SUB_NAME  => '30|30 (MB/s) (' . (30 * 8) . ' Mbps)',
                Enum::OPTION_SUB_ORDER => Enum::OPTION_SUB_ORDER_DEFAULT,
            ],
            [
                Enum::OPTION_SUB_NAME  => '40|40 (MB/s) (' . (40 * 8) . ' Mbps)',
                Enum::OPTION_SUB_ORDER => Enum::OPTION_SUB_ORDER_DEFAULT,
            ],
            [
                Enum::OPTION_SUB_NAME  => '50|50 (MB/s) (' . (50 * 8) . ' Mbps)',
                Enum::OPTION_SUB_ORDER => Enum::OPTION_SUB_ORDER_DEFAULT,
            ],
        ];
    }

    public function getConfigurableOptions()
    {
        $configOptions = [];
        if ($this->configuration()->isQemu())
        {
            $configOptions[] = [
                Enum::OPTION_NAME         => ConfigurableOption::SOCKETS.'|CPU Sockets',
                Enum::OPTION_TYPE         => Enum::OPTION_TYPE_QUANTITY,
                Enum::OPTION_QUANTITY_MIN => 1,
                Enum::OPTION_QUANTITY_MAX => 100,
                Enum::CONFIG_SUB_OPTIONS  => [
                    [
                        Enum::OPTION_SUB_NAME  => 'Unit|Unit',
                        Enum::OPTION_SUB_ORDER => Enum::OPTION_SUB_ORDER_DEFAULT,
                    ]
                ]
            ];
            $configOptions[] = [
                Enum::OPTION_NAME         => ConfigurableOption::CORES.'|CPU Cores',
                Enum::OPTION_TYPE         => Enum::OPTION_TYPE_QUANTITY,
                Enum::OPTION_QUANTITY_MIN => 1,
                Enum::OPTION_QUANTITY_MAX => 10,
                Enum::CONFIG_SUB_OPTIONS  => [
                    [
                        Enum::OPTION_SUB_NAME  => 'Unit|Unit',
                        Enum::OPTION_SUB_ORDER => Enum::OPTION_SUB_ORDER_DEFAULT,
                    ]
                ]
            ];
        }
        $configOptions[] = [
            Enum::OPTION_NAME         =>  ConfigurableOption::CPU_LIMIT.'|CPU Limit',
            Enum::OPTION_TYPE         => Enum::OPTION_TYPE_QUANTITY,
            Enum::OPTION_QUANTITY_MIN => 0,
            Enum::OPTION_QUANTITY_MAX => 100,
            Enum::CONFIG_SUB_OPTIONS  => [
                [
                    Enum::OPTION_SUB_NAME  => 'Unit|Unit',
                    Enum::OPTION_SUB_ORDER => Enum::OPTION_SUB_ORDER_DEFAULT,
                ]
            ]
        ];
        $configOptions[] = [
            Enum::OPTION_NAME         => ConfigurableOption::CPU_UNITS.'|CPU Weight Limit',
            Enum::OPTION_TYPE         => Enum::OPTION_TYPE_QUANTITY,
            Enum::OPTION_QUANTITY_MIN => 1024,
            Enum::OPTION_QUANTITY_MAX => 99999,
            Enum::CONFIG_SUB_OPTIONS  => [
                [
                    Enum::OPTION_SUB_NAME  => 'Unit|Unit',
                    Enum::OPTION_SUB_ORDER => Enum::OPTION_SUB_ORDER_DEFAULT,
                ]
            ]
        ];
        $unit            = strtoupper($this->configuration()->getMemoryUnit());
        $min             = 128;
        $max             = 1024 * 10;
        if ($this->configuration()->getMemoryUnit() == 'gb')
        {
            $min = 1;
            $max = 10;
        }
        $configOptions[] = [
            Enum::OPTION_NAME         => ConfigurableOption::MEMORY.'|Memory',
            Enum::OPTION_TYPE         => Enum::OPTION_TYPE_QUANTITY,
            Enum::OPTION_QUANTITY_MIN => $min,
            Enum::OPTION_QUANTITY_MAX => $max,
            Enum::CONFIG_SUB_OPTIONS  => [
                [
                    Enum::OPTION_SUB_NAME  => "{$unit}|{$unit}",
                    Enum::OPTION_SUB_ORDER => Enum::OPTION_SUB_ORDER_DEFAULT,
                ]
            ]
        ];
        if ($this->configuration()->isLxc())
        {
            $unit = strtoupper($this->configuration()->getSwapUnit());
            $min  = 128;
            $max  = 1024 * 10;
            if ($this->configuration()->getSwapUnit() == 'gb')
            {
                $min = 1;
                $max = 10;
            }
            $configOptions[] = [
                Enum::OPTION_NAME         => ConfigurableOption::SWAP.'|SWAP',
                Enum::OPTION_TYPE         => Enum::OPTION_TYPE_QUANTITY,
                Enum::OPTION_QUANTITY_MIN => $min,
                Enum::OPTION_QUANTITY_MAX => $max,
                Enum::CONFIG_SUB_OPTIONS  => [
                    [
                        Enum::OPTION_SUB_NAME  => "{$unit}|{$unit}",
                        Enum::OPTION_SUB_ORDER => Enum::OPTION_SUB_ORDER_DEFAULT,
                    ]
                ]
            ];
        }
        $unit = strtoupper($this->configuration()->getStorageUnit());
        $min  = 128;
        $max  = 1024 * 1000;
        if ($this->configuration()->getStorageUnit() == 'gb' || $this->configuration()->getStorageUnit() == 'tb')
        {
            $min = 1;
            $max = 1000;
        }
        $configOptions[] = [
            Enum::OPTION_NAME         => ConfigurableOption::STORAGE.'|Storage',
            Enum::OPTION_TYPE         => Enum::OPTION_TYPE_QUANTITY,
            Enum::OPTION_QUANTITY_MIN => $min,
            Enum::OPTION_QUANTITY_MAX => $max,
            Enum::CONFIG_SUB_OPTIONS  => [
                [
                    Enum::OPTION_SUB_NAME  => "{$unit}|{$unit}",
                    Enum::OPTION_SUB_ORDER => Enum::OPTION_SUB_ORDER_DEFAULT,
                ]
            ]
        ];
        $configOptions[] = [
            Enum::OPTION_NAME         => ConfigurableOption::IPV4.'|IPv4 Addresses',
            Enum::OPTION_TYPE         => Enum::OPTION_TYPE_QUANTITY,
            Enum::OPTION_QUANTITY_MIN => 0,
            Enum::OPTION_QUANTITY_MAX => 100,
            Enum::CONFIG_SUB_OPTIONS  => [
                [
                    Enum::OPTION_SUB_NAME  => 'Unit|Unit',
                    Enum::OPTION_SUB_ORDER => Enum::OPTION_SUB_ORDER_DEFAULT,
                ]
            ]
        ];
        $configOptions[] = [
            Enum::OPTION_NAME         => ConfigurableOption::IPV6.'|IPv6 Addresses',
            Enum::OPTION_TYPE         => Enum::OPTION_TYPE_QUANTITY,
            Enum::OPTION_QUANTITY_MIN => 0,
            Enum::OPTION_QUANTITY_MAX => 100,
            Enum::CONFIG_SUB_OPTIONS  => [
                [
                    Enum::OPTION_SUB_NAME  => 'Unit|Unit',
                    Enum::OPTION_SUB_ORDER => Enum::OPTION_SUB_ORDER_DEFAULT,
                ]
            ]
        ];
        $configOptions[] = [
            Enum::OPTION_NAME         =>  ConfigurableOption::BACKUPS_SIZE.'|Backups Size',
            Enum::OPTION_TYPE         => Enum::OPTION_TYPE_QUANTITY,
            Enum::OPTION_QUANTITY_MIN => 0,
            Enum::OPTION_QUANTITY_MAX => 10 * 100,
            Enum::CONFIG_SUB_OPTIONS  => [
                [
                    Enum::OPTION_SUB_NAME  => 'GB|GB',
                    Enum::OPTION_SUB_ORDER => Enum::OPTION_SUB_ORDER_DEFAULT,
                ]
            ]
        ];
        $configOptions[] = [
            Enum::OPTION_NAME         =>  ConfigurableOption::BACKUPS_FILES.'|Backups Files Limit',
            Enum::OPTION_TYPE         => Enum::OPTION_TYPE_QUANTITY,
            Enum::OPTION_QUANTITY_MIN => 0,
            Enum::OPTION_QUANTITY_MAX => 100,
            Enum::CONFIG_SUB_OPTIONS  => [
                [
                    Enum::OPTION_SUB_NAME  => 'Unit|Unit',
                    Enum::OPTION_SUB_ORDER => Enum::OPTION_SUB_ORDER_DEFAULT,
                ]
            ]
        ];
        $configOptions[] = [
            Enum::OPTION_NAME         =>  ConfigurableOption::SNAPSHOTS.'|Snapshots',
            Enum::OPTION_TYPE         => Enum::OPTION_TYPE_QUANTITY,
            Enum::OPTION_QUANTITY_MIN => 0,
            Enum::OPTION_QUANTITY_MAX => 100,
            Enum::CONFIG_SUB_OPTIONS  => [
                [
                    Enum::OPTION_SUB_NAME  => 'Unit|Unit',
                    Enum::OPTION_SUB_ORDER => Enum::OPTION_SUB_ORDER_DEFAULT,
                ]
            ]
        ];
        $configOptions[] = [
            Enum::OPTION_NAME         => ConfigurableOption::BANDWIDTH.'|Bandwidth',
            Enum::OPTION_TYPE         => Enum::OPTION_TYPE_QUANTITY,
            Enum::OPTION_QUANTITY_MIN => 0,
            Enum::OPTION_QUANTITY_MAX => 10 * 100,
            Enum::CONFIG_SUB_OPTIONS  => [
                [
                    Enum::OPTION_SUB_NAME  => 'GB|GB',
                    Enum::OPTION_SUB_ORDER => Enum::OPTION_SUB_ORDER_DEFAULT,
                ]
            ]
        ];
        $configOptions[] = [
            Enum::OPTION_NAME => ConfigurableOption::NETWORK_RATE.'|Network Rate',
            Enum::OPTION_TYPE => Enum::OPTION_TYPE_DROPDOWN,
        ];

        if ($this->configuration()->isQemu())
        {
            $configOptions[] = [
                Enum::OPTION_NAME         => ConfigurableOption::VCPUS.'|VCPUs',
                Enum::OPTION_TYPE         => Enum::OPTION_TYPE_QUANTITY,
                Enum::OPTION_QUANTITY_MIN => 0,
                Enum::OPTION_QUANTITY_MAX => 100,
                Enum::CONFIG_SUB_OPTIONS  => [
                    [
                        Enum::OPTION_SUB_NAME  => 'vCPU|vCPU',
                        Enum::OPTION_SUB_ORDER => Enum::OPTION_SUB_ORDER_DEFAULT,
                    ]
                ]
            ];

        }
        $configOptions[] = [
            Enum::OPTION_NAME         =>  ConfigurableOption::VIRTUAL_NETWORKS.'|Virtual Networks',
            Enum::OPTION_TYPE         => Enum::OPTION_TYPE_QUANTITY,
            Enum::OPTION_QUANTITY_MIN => 0,
            Enum::OPTION_QUANTITY_MAX => 100,
            Enum::CONFIG_SUB_OPTIONS  => [
                [
                    Enum::OPTION_SUB_NAME  => 'Unit|Unit',
                    Enum::OPTION_SUB_ORDER => Enum::OPTION_SUB_ORDER_DEFAULT,
                ]
            ]
        ];
        return $configOptions;
    }
}
