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 = "APNConfig", description = "Details of APN Config.")
public class APNConfig extends PayloadOperation {

    @ApiModelProperty(name = "apnConfigurations", value = "Case 64 encode .pem file content.", required = true )
    private List<LegacyAPNConfiguration> apnConfigurations;

    @Override
    public void validateRequest() throws ProfileConfigurationException {

        if (apnConfigurations == null || apnConfigurations.isEmpty()) {
            throw new ProfileConfigurationException("APN configurations are empty");
        }

        for (LegacyAPNConfiguration apnConfiguration : apnConfigurations) {

            if (StringUtils.isEmpty(apnConfiguration.getApn())) {
                throw new ProfileConfigurationException("APN name is empty");
            }

            if (StringUtils.isEmpty(apnConfiguration.getUsername())) {
                throw new ProfileConfigurationException("APN username is empty");
            }
        }
    }

    public List<LegacyAPNConfiguration> getApnConfigurations() {
        return apnConfigurations;
    }

    public void setApnConfigurations(List<LegacyAPNConfiguration> apnConfigurations) {
        this.apnConfigurations = apnConfigurations;
    }
}
