package api.unicore.component;
 
import static api.util.ComponentConstants.STRING_NULL;
import static api.util.ComponentConstants.STRING_NULL_CODE;
import static org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion.NON_NULL;
 
import api.UnoComponent;
import api.unicore.component_manual.UserAccessInfo;
import api.util.StringFormat;
import iapp.services.ServerObject;
import iapp.util.audit.AuditHelper;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.FormParam;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.codehaus.jackson.annotate.JsonPropertyOrder;
import org.codehaus.jackson.map.annotate.JsonDeserialize;
import org.codehaus.jackson.map.annotate.JsonSerialize;
 
/**
 * @author CodeGen
 * @company UnitedThinkers
 * @since 2012/10/15
 */
 
@JsonSerialize(include=NON_NULL)
@XmlType(propOrder={"ipAddressList", "countryCodeList", "ipAddressAccessPolicy", "countryCodeAccessPolicy"})
@JsonPropertyOrder({"ipAddressList", "countryCodeList", "ipAddressAccessPolicy", "countryCodeAccessPolicy"})
@XmlAccessorType(XmlAccessType.NONE)
@XmlSeeAlso(UserAccessInfo.class)
public abstract class AbstractUserAccessInfo extends UnoComponent<unicore.model.User> {
 
    @FormParam("ipAddressList")
    @StringFormat
    @DefaultValue(STRING_NULL_CODE)
    protected String ipAddressList;
 
    @FormParam("countryCodeList")
    @StringFormat
    @DefaultValue(STRING_NULL_CODE)
    protected String countryCodeList;
 
    @FormParam("ipAddressAccessPolicy")
    @StringFormat
    @DefaultValue(STRING_NULL_CODE)
    protected String ipAddressAccessPolicy;
 
    @FormParam("countryCodeAccessPolicy")
    @StringFormat
    @DefaultValue(STRING_NULL_CODE)
    protected String countryCodeAccessPolicy;
 
 
    public AbstractUserAccessInfo(){
        super();
        applyDefaults();
    }
 
    public AbstractUserAccessInfo(unicore.model.User object){
        super(object);
    }
 
 
    private void applyDefaults() {
        if (!isProxyObject()) {
            ipAddressList = STRING_NULL;
            countryCodeList = STRING_NULL;
            ipAddressAccessPolicy = STRING_NULL;
            countryCodeAccessPolicy = STRING_NULL;
        }
    }
 
    @Override
    public void from() {
        fromInternal();
        super.from();
    }
 
    protected abstract void fromInternal();
    @Override
    public abstract void to();
    @Override
    public abstract void initializeNew();
 
    @Override
    public String toString(){
        StringBuilder sb = new StringBuilder();
        sb.append("accessInfo: {");
        sb.append("ipAddressList: ");
        sb.append(ipAddressList);
        sb.append(',').append(' ');
        sb.append("countryCodeList: ");
        sb.append(countryCodeList);
        sb.append(',').append(' ');
        sb.append("ipAddressAccessPolicy: ");
        sb.append(ipAddressAccessPolicy);
        sb.append(',').append(' ');
        sb.append("countryCodeAccessPolicy: ");
        sb.append(countryCodeAccessPolicy);
        sb.append('}');
        return sb.toString();
    }
 
 
    @XmlAttribute(name="ipAddressList")
    @XmlJavaTypeAdapter(value=api.util.StringAdapter.class, type=String.class)
    @FormParam("ipAddressList")
    @StringFormat
    @JsonDeserialize(using = api.util.StringDeserializer.class)
    public String getIpAddressList(){
        return ipAddressList;
    }
 
    public void setIpAddressList(String value){
        this.ipAddressList = value;
    }
 
    @XmlAttribute(name="countryCodeList")
    @XmlJavaTypeAdapter(value=api.util.StringAdapter.class, type=String.class)
    @FormParam("countryCodeList")
    @StringFormat
    @JsonDeserialize(using = api.util.StringDeserializer.class)
    public String getCountryCodeList(){
        return countryCodeList;
    }
 
    public void setCountryCodeList(String value){
        this.countryCodeList = value;
    }
 
    @XmlAttribute(name="ipAddressAccessPolicy")
    @XmlJavaTypeAdapter(value=api.util.StringAdapter.class, type=String.class)
    @FormParam("ipAddressAccessPolicy")
    @StringFormat
    @JsonDeserialize(using = api.util.StringDeserializer.class)
    public String getIpAddressAccessPolicy(){
        return ipAddressAccessPolicy;
    }
 
    public void setIpAddressAccessPolicy(String value){
        this.ipAddressAccessPolicy = value;
    }
 
    @XmlAttribute(name="countryCodeAccessPolicy")
    @XmlJavaTypeAdapter(value=api.util.StringAdapter.class, type=String.class)
    @FormParam("countryCodeAccessPolicy")
    @StringFormat
    @JsonDeserialize(using = api.util.StringDeserializer.class)
    public String getCountryCodeAccessPolicy(){
        return countryCodeAccessPolicy;
    }
 
    public void setCountryCodeAccessPolicy(String value){
        this.countryCodeAccessPolicy = value;
    }
 
 
    public void audit(AuditHelper helper, ServerObject object) {
        unicore.model.User s_object = (unicore.model.User) object;
        helper.audit("ipAddressList", ipAddressList, s_object.getIpAddressAccessList());
        helper.audit("countryCodeList", countryCodeList, s_object.getCountryCodeAccessList());
        helper.audit("ipAddressAccessPolicy", ipAddressAccessPolicy, s_object.getIpAddressAccessPolicyCl() == null ? null : s_object.getIpAddressAccessPolicyCl().getValue());
        helper.audit("countryCodeAccessPolicy", countryCodeAccessPolicy, s_object.getCountryCodeAccessPolicyCl() == null ? null : s_object.getCountryCodeAccessPolicyCl().getValue());
 
    }
 
    public static String objectTypeCode(){
        return "access-info";
    }
 
}