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 = "LDAP",
        description = "Information related to LDAP configuration.")
public class LDAP extends PayloadOperation {

    @ApiModelProperty(name = "accountDescription",
            value = "LDAP account Description.", required = true)
    private String accountDescription;
    @ApiModelProperty(name = "accountHostName",
            value = "LDAP account host name.", required = true)
    private String accountHostName;
    @ApiModelProperty(name = "accountUseSSL",
            value = "LDAP account Use ssl.", required = true)
    private Boolean accountUseSSL;
    @ApiModelProperty(name = "accountUsername",
            value = "LDAP account user name.", required = true)
    private String accountUsername;
    @ApiModelProperty(name = "accountPassword",
            value = "LDAP account password.", required = true)
    private String accountPassword;
    @ApiModelProperty(name = "ldapSearchSettings",
            value = "LDAP account search setting.", required = true)
    private List<LDAPSearchSetting> ldapSearchSettings;

    @Override
    public void validateRequest() throws ProfileConfigurationException {

        if (accountHostName == null || accountHostName.isEmpty()) {
            throw new ProfileConfigurationException("Account host name is empty");
        }

        if (accountUseSSL == null) {
            throw new ProfileConfigurationException("Use SSL is empty");
        }

        if (ldapSearchSettings == null || ldapSearchSettings.isEmpty()) {
            throw new ProfileConfigurationException("Provide at least one set of LDAP search settings");
        }

        for (LDAPSearchSetting ldapSearchSetting : ldapSearchSettings) {

            if (ldapSearchSetting.getSearchSettingScope() == null) {
                throw new ProfileConfigurationException("Search setting scope is empty");
            }

            if (StringUtils.isEmpty(ldapSearchSetting.getSearchSettingSearchBase())) {
                throw new ProfileConfigurationException("Search setting base is empty");
            }
        }
    }

    public String getAccountDescription() {
        return accountDescription;
    }

    public void setAccountDescription(String accountDescription) {
        this.accountDescription = accountDescription;
    }

    public String getAccountHostName() {
        return accountHostName;
    }

    public void setAccountHostName(String accountHostName) {
        this.accountHostName = accountHostName;
    }

    public Boolean getAccountUseSSL() {
        return accountUseSSL;
    }

    public void setAccountUseSSL(Boolean accountUseSSL) {
        this.accountUseSSL = accountUseSSL;
    }

    public String getAccountUsername() {
        return accountUsername;
    }

    public void setAccountUsername(String accountUsername) {
        this.accountUsername = accountUsername;
    }

    public String getAccountPassword() {
        return accountPassword;
    }

    public void setAccountPassword(String accountPassword) {
        this.accountPassword = accountPassword;
    }

    public List<LDAPSearchSetting> getLdapSearchSettings() {
        return ldapSearchSettings;
    }

    public void setLdapSearchSettings(List<LDAPSearchSetting> ldapSearchSettings) {
        this.ldapSearchSettings = ldapSearchSettings;
    }
}
