package org.wso2.carbon.device.mgt.ios.payload.beans;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang.StringUtils;
import org.wso2.carbon.device.mgt.ios.payload.exception.ProfileConfigurationException;

import java.util.List;

@ApiModel(value = "VPN",
        description = "Information related to VPN Configuration.")
public class VPN extends PayloadOperation {

    @ApiModelProperty(name = "userDefinedName",
            value = "User Defined name.", required = true)
    private String userDefinedName;
    @ApiModelProperty(name = "overridePrimary",
            value = "Override Primary status.", required = true)
    private Boolean overridePrimary;
    @ApiModelProperty(name = "vpnType",
            value = "Type of VPN.", required = true)
    private VPNType vpnType;
    @ApiModelProperty(name = "onDemandEnabled",
            value = "Enable/Disable onDemand.", required = true)
    private Boolean onDemandEnabled;
    @ApiModelProperty(name = "onDemandMatchDomainsAlways",
            value = "Lost of onDemandMatchDomainsAlways.", required = true)
    private List<String> onDemandMatchDomainsAlways;
    @ApiModelProperty(name = "onDemandMatchDomainsNever",
            value = "List of device Ids to be need to execute VPN operation.", required = true)
    private List<String> onDemandMatchDomainsNever;
    @ApiModelProperty(name = "onDemandMatchDomainsOnRetry",
            value = "List of onDemandMatchDomainsOnRetry.", required = true)
    private List<String> onDemandMatchDomainsOnRetry;
    @ApiModelProperty(name = "onDemandRules",
            value = "List of OnDemandRules.", required = true)
    private List<OnDemandRule> onDemandRules;
    @ApiModelProperty(name = "vendorConfigs",
            value = "List of vendor configurations.", required = true)
    private List<VendorConfig> vendorConfigs;
    @ApiModelProperty(name = "pptp",
            value = "PPTP profile type.", required = true)
    private PPP ppp;
    @ApiModelProperty(name = "ipSec",
            value = "ipSec.", required = true)
    private IPSec ipSec;
    @ApiModelProperty(name = "ikEv2",
            value = "ikEv2.", required = true)
    private IKEv2 ikEv2;

    private PulseSecure pulseSecure;

    @Override
    public void validateRequest() throws ProfileConfigurationException {

        if (StringUtils.isEmpty(userDefinedName)) {
            throw new ProfileConfigurationException("User defined name is empty");
        }

        if (overridePrimary == null) {
            throw new ProfileConfigurationException("Override primary is empty");
        }

        if (vpnType == null) {
            throw new ProfileConfigurationException("VPN type is empty");
        }

        if ((vpnType == VPNType.PPTP || vpnType == VPNType.L2TP) && ppp == null) {
            throw new ProfileConfigurationException("PPP information needs to be provided for VPN type " +
                    vpnType.toString());
        }

        if (vpnType == VPNType.IPSec && ipSec == null) {
            throw new ProfileConfigurationException("IPSec information needs to be provided for IPSec property");
        }

        if (vpnType == VPNType.IKEv2 && ikEv2 == null) {
            throw new ProfileConfigurationException("IKEv2 information needs to be provided for IKEv2 property");
        }

        if (vpnType == VPNType.PulseSecure && pulseSecure == null) {
            throw new ProfileConfigurationException("PulseSecure information needs to be provided for PulseSecure " +
                    "property");
        }

        if (onDemandEnabled == null) {
            throw new ProfileConfigurationException("On demand enabled field is empty");
        }

    }

    public String getUserDefinedName() {
        return userDefinedName;
    }

    public void setUserDefinedName(String userDefinedName) {
        this.userDefinedName = userDefinedName;
    }

    public Boolean getOverridePrimary() {
        return overridePrimary;
    }

    public void setOverridePrimary(Boolean overridePrimary) {
        this.overridePrimary = overridePrimary;
    }

    public VPNType getVpnType() {
        return vpnType;
    }

    public void setVpnType(VPNType vpnType) {
        this.vpnType = vpnType;
    }

    public Boolean getOnDemandEnabled() {
        return onDemandEnabled;
    }

    public void setOnDemandEnabled(Boolean onDemandEnabled) {
        this.onDemandEnabled = onDemandEnabled;
    }

    public List<String> getOnDemandMatchDomainsAlways() {
        return onDemandMatchDomainsAlways;
    }

    public void setOnDemandMatchDomainsAlways(List<String> onDemandMatchDomainsAlways) {
        this.onDemandMatchDomainsAlways = onDemandMatchDomainsAlways;
    }

    public List<String> getOnDemandMatchDomainsNever() {
        return onDemandMatchDomainsNever;
    }

    public void setOnDemandMatchDomainsNever(List<String> onDemandMatchDomainsNever) {
        this.onDemandMatchDomainsNever = onDemandMatchDomainsNever;
    }

    public List<String> getOnDemandMatchDomainsOnRetry() {
        return onDemandMatchDomainsOnRetry;
    }

    public void setOnDemandMatchDomainsOnRetry(List<String> onDemandMatchDomainsOnRetry) {
        this.onDemandMatchDomainsOnRetry = onDemandMatchDomainsOnRetry;
    }

    public List<OnDemandRule> getOnDemandRules() {
        return onDemandRules;
    }

    public void setOnDemandRules(List<OnDemandRule> onDemandRules) {
        this.onDemandRules = onDemandRules;
    }

    public List<VendorConfig> getVendorConfigs() {
        return vendorConfigs;
    }

    public void setVendorConfigs(List<VendorConfig> vendorConfigs) {
        this.vendorConfigs = vendorConfigs;
    }

    public PPP getPpp() {
        return ppp;
    }

    public void setPpp(PPP ppp) {
        this.ppp = ppp;
    }

    public IPSec getIpSec() {
        return ipSec;
    }

    public void setIpSec(IPSec ipSec) {
        this.ipSec = ipSec;
    }

    public IKEv2 getIkEv2() {
        return ikEv2;
    }

    public void setIkEv2(IKEv2 ikEv2) {
        this.ikEv2 = ikEv2;
    }

    public PulseSecure getPulseSecure() {
        return pulseSecure;
    }

    public void setPulseSecure(PulseSecure pulseSecure) {
        this.pulseSecure = pulseSecure;
    }

}
