package api.unicore.component.fees;
 
import static api.util.ComponentConstants.BOOLEAN_NULL;
import static api.util.ComponentConstants.BOOLEAN_NULL_CODE;
import static api.util.ComponentConstants.INTEGER_NULL;
import static api.util.ComponentConstants.INTEGER_NULL_CODE;
import static api.util.ComponentConstants.LONG_NULL;
import static api.util.ComponentConstants.LONG_NULL_CODE;
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.fees_manual.MerchantFee;
import api.util.BooleanFormat;
import api.util.IntegerFormat;
import api.util.LongFormat;
import api.util.StringFormat;
import iapp.services.ServerObject;
import iapp.util.audit.AuditHelper;
import javax.validation.constraints.Min;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
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 [Dmytro Sedukhin]
 * @company UnitedThinkers
 * @since 2012/09/03
 */
 
@JsonSerialize(include=NON_NULL)
@XmlType(propOrder={"type", "isActive", "refCode", "description", "parameters", "feeTemplateCode", "merchantAccountCode"})
@JsonPropertyOrder({"type", "isActive", "refCode", "description", "parameters", "feeTemplateCode", "merchantAccountCode"})
@XmlAccessorType(XmlAccessType.NONE)
@XmlSeeAlso(MerchantFee.class)
public abstract class AbstractMerchantFee extends UnoComponent<unicore.model.MerchantFee> {
 
    @FormParam("type")
    @StringFormat
    @DefaultValue(STRING_NULL_CODE)
    protected String type;
 
    @FormParam("isActive")
    @BooleanFormat
    @DefaultValue(BOOLEAN_NULL_CODE)
    protected Boolean isActive;
 
    @FormParam("refCode")
    @StringFormat
    @DefaultValue(STRING_NULL_CODE)
    protected String refCode;
 
    @FormParam("description")
    @StringFormat
    @DefaultValue(STRING_NULL_CODE)
    protected String description;
 
    @FormParam("parameters")
    @StringFormat
    @DefaultValue(STRING_NULL_CODE)
    protected String parameters;
 
    @FormParam("feeTemplateCode")
    @LongFormat
    @DefaultValue(LONG_NULL_CODE)
    protected Long feeTemplateCode;
 
    @FormParam("merchantAccountCode")
    @IntegerFormat
    @DefaultValue(INTEGER_NULL_CODE)
    protected Integer merchantAccountCode;
 
 
    public AbstractMerchantFee(){
        super();
        applyDefaults();
    }
 
    public AbstractMerchantFee(unicore.model.MerchantFee object){
        super(object);
    }
 
 
    private void applyDefaults() {
        if (!isProxyObject()) {
            type = STRING_NULL;
            isActive = BOOLEAN_NULL;
            refCode = STRING_NULL;
            description = STRING_NULL;
            parameters = STRING_NULL;
            feeTemplateCode = LONG_NULL;
            merchantAccountCode = INTEGER_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("fee: {");
        sb.append("type: ");
        sb.append(type);
        sb.append(',').append(' ');
        sb.append("isActive: ");
        sb.append(isActive);
        sb.append(',').append(' ');
        sb.append("refCode: ");
        sb.append(refCode);
        sb.append(',').append(' ');
        sb.append("description: ");
        sb.append(description);
        sb.append(',').append(' ');
        sb.append("parameters: ");
        sb.append(parameters);
        sb.append(',').append(' ');
        sb.append("feeTemplateCode: ");
        sb.append(feeTemplateCode);
        sb.append(',').append(' ');
        sb.append("merchantAccountCode: ");
        sb.append(merchantAccountCode);
        sb.append('}');
        return sb.toString();
    }
 
 
    @XmlAttribute(name="type")
    @XmlJavaTypeAdapter(value=api.util.StringAdapter.class, type=String.class)
    @FormParam("type")
    @StringFormat
    @JsonDeserialize(using = api.util.StringDeserializer.class)
    public String getType(){
        return type;
    }
 
    public void setType(String value){
        this.type = value;
    }
 
    @XmlAttribute(name="isActive")
    @FormParam("isActive")
    @BooleanFormat
    public Boolean getIsActive(){
        return isActive;
    }
 
    public void setIsActive(Boolean value){
        this.isActive = value;
    }
 
    @XmlAttribute(name="refCode")
    @XmlJavaTypeAdapter(value=api.util.StringAdapter.class, type=String.class)
    @FormParam("refCode")
    @StringFormat
    @JsonDeserialize(using = api.util.StringDeserializer.class)
    @Size(max = 20)
    @Pattern(regexp = unipay.validator.PatternName.REFERENCE)
    public String getRefCode(){
        return refCode;
    }
 
    public void setRefCode(String value){
        this.refCode = value;
    }
 
    @XmlAttribute(name="description")
    @XmlJavaTypeAdapter(value=api.util.StringAdapter.class, type=String.class)
    @FormParam("description")
    @StringFormat
    @JsonDeserialize(using = api.util.StringDeserializer.class)
    @Size(max = 255)
    @Pattern(regexp = unipay.validator.PatternName.TEXT)
    public String getDescription(){
        return description;
    }
 
    public void setDescription(String value){
        this.description = value;
    }
 
    @XmlAttribute(name="parameters")
    @XmlJavaTypeAdapter(value=api.util.StringAdapter.class, type=String.class)
    @FormParam("parameters")
    @StringFormat
    @JsonDeserialize(using = api.util.StringDeserializer.class)
    public String getParameters(){
        return parameters;
    }
 
    public void setParameters(String value){
        this.parameters = value;
    }
 
    @XmlAttribute(name="feeTemplateCode")
    @XmlJavaTypeAdapter(value=api.util.LongAdapter.class, type=Long.class)
    @FormParam("feeTemplateCode")
    @LongFormat
    @JsonDeserialize(using=api.util.NumberDeserializer.class)
    @Min(0)
    public Long getFeeTemplateCode(){
        return feeTemplateCode;
    }
 
    public void setFeeTemplateCode(Long value){
        this.feeTemplateCode = value;
    }
 
    @XmlAttribute(name="merchantAccountCode")
    @XmlJavaTypeAdapter(value=api.util.IntegerAdapter.class, type=Integer.class)
    @FormParam("merchantAccountCode")
    @IntegerFormat
    @JsonDeserialize(using=api.util.NumberDeserializer.class)
    public Integer getMerchantAccountCode(){
        return merchantAccountCode;
    }
 
    public void setMerchantAccountCode(Integer value){
        this.merchantAccountCode = value;
    }
 
 
    public void audit(AuditHelper helper, ServerObject object) {
        unicore.model.MerchantFee s_object = (unicore.model.MerchantFee) object;
        helper.audit("type", type, s_object.getType());
        helper.audit("isActive", isActive, s_object.getIsActive());
        helper.audit("refCode", refCode, s_object.getRefCode());
        helper.audit("description", description, s_object.getDescription());
        helper.audit("parameters", parameters, s_object.getParameters());
        helper.audit("feeTemplateCode", feeTemplateCode, s_object.getFeeTemplateCode());
        helper.audit("merchantAccountCode", merchantAccountCode, s_object.getMerchantAccountCode());
 
    }
 
    public static String objectTypeCode(){
        return "merchant-fee";
    }
 
}