package api.unibill.component;
 
import static api.util.ComponentConstants.DATE_NULL;
import static api.util.ComponentConstants.DATE_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_manual.Plan;
import api.util.BooleanFormat;
import api.util.DateFormat;
import api.util.IntegerFormat;
import api.util.LongFormat;
import api.util.StringFormat;
import java.util.Date;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
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;
import unipay.fields_manual.Fields;
import unipay.validator.CustomValidator;
import unipay.validator.EnumValidator;
 
/**
 * @author CodeGen [Anton Shershnov]
 * @company UnitedThinkers
 * @since 2018/06/05
 */
 
@JsonSerialize(include=NON_NULL)
@XmlType(propOrder={"id", "code", "accountId", "createDate", "name", "billingCycleType", "amount", "isActive", "taxAmount"})
@JsonPropertyOrder({"id", "code", "accountId", "createDate", "name", "billingCycleType", "amount", "isActive", "taxAmount"})
@XmlAccessorType(XmlAccessType.NONE)
@XmlSeeAlso(Plan.class)
@CustomValidator
public abstract class AbstractPlan extends UnoComponent<unibill.model.Plan> {
 
    @FormParam("id")
    @LongFormat
    @DefaultValue(LONG_NULL_CODE)
    protected Long id;
 
    @FormParam("code")
    @StringFormat
    @DefaultValue(STRING_NULL_CODE)
    protected String code;
 
    @FormParam("accountId")
    @IntegerFormat
    @DefaultValue(INTEGER_NULL_CODE)
    protected Integer accountId;
 
    @FormParam("createDate")
    @DateFormat
    @DefaultValue(DATE_NULL_CODE)
    protected Date createDate;
 
    @FormParam("name")
    @StringFormat
    @DefaultValue(STRING_NULL_CODE)
    protected String name;
 
    @FormParam("billingCycleType")
    @StringFormat
    protected String billingCycleType;
 
    @FormParam("amount")
    @IntegerFormat
    @DefaultValue(INTEGER_NULL_CODE)
    protected Integer amount;
 
    @FormParam("isActive")
    @BooleanFormat
    protected Boolean isActive;
 
    @FormParam("taxAmount")
    @IntegerFormat
    @DefaultValue(INTEGER_NULL_CODE)
    protected Integer taxAmount;
 
 
    public AbstractPlan(){
        super();
        applyDefaults();
    }
 
    public AbstractPlan(unibill.model.Plan object){
        super(object);
    }
 
 
    private void applyDefaults() {
        if (!isProxyObject()) {
            id = LONG_NULL;
            code = STRING_NULL;
            accountId = INTEGER_NULL;
            createDate = DATE_NULL;
            name = STRING_NULL;
            amount = INTEGER_NULL;
            taxAmount = INTEGER_NULL;
        }
        billingCycleType = M;
        isActive = true;
    }
 
    @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("plan: {");
        sb.append("id: ");
        sb.append(id);
        sb.append(',').append(' ');
        sb.append("code: ");
        sb.append(code);
        sb.append(',').append(' ');
        sb.append("accountId: ");
        sb.append(accountId);
        sb.append(',').append(' ');
        sb.append("createDate: ");
        sb.append(createDate);
        sb.append(',').append(' ');
        sb.append("name: ");
        sb.append(name);
        sb.append(',').append(' ');
        sb.append("billingCycleType: ");
        sb.append(billingCycleType);
        sb.append(',').append(' ');
        sb.append("amount: ");
        sb.append(amount);
        sb.append(',').append(' ');
        sb.append("isActive: ");
        sb.append(isActive);
        sb.append(',').append(' ');
        sb.append("taxAmount: ");
        sb.append(taxAmount);
        sb.append('}');
        return sb.toString();
    }
 
 
    @XmlAttribute(name="id")
    @XmlJavaTypeAdapter(value=api.util.LongAdapter.class, type=Long.class)
    @FormParam("id")
    @LongFormat
    @JsonDeserialize(using=api.util.NumberDeserializer.class)
    public Long getId(){
        return id;
    }
 
 
    @XmlAttribute(name="code")
    @XmlJavaTypeAdapter(value=api.util.StringAdapter.class, type=String.class)
    @FormParam("code")
    @StringFormat
    @JsonDeserialize(using = api.util.StringDeserializer.class)
    @Size(max = 60)
    @Pattern(regexp = unipay.validator.PatternName.CODE)
    public String getCode(){
        return code;
    }
 
    public void setCode(String value){
        this.code = value;
    }
 
    @XmlAttribute(name="accountId")
    @XmlJavaTypeAdapter(value=api.util.IntegerAdapter.class, type=Integer.class)
    @FormParam("accountId")
    @IntegerFormat
    @JsonDeserialize(using=api.util.NumberDeserializer.class)
    @NotNull
    public Integer getAccountId(){
        return accountId;
    }
 
    public void setAccountId(Integer value){
        this.accountId = value;
    }
 
    @XmlAttribute(name="createDate")
    @XmlJavaTypeAdapter(api.util.DateTimeAdapter.class)
    @FormParam("createDate")
    @DateFormat
    @JsonSerialize(using=api.util.DateTimeSerializer.class, include = NON_NULL)
    @JsonDeserialize(using=api.util.DateDeserializer.class)
    public Date getCreateDate(){
        return createDate;
    }
 
 
    @XmlAttribute(name="name")
    @XmlJavaTypeAdapter(value=api.util.StringAdapter.class, type=String.class)
    @FormParam("name")
    @StringFormat
    @JsonDeserialize(using = api.util.StringDeserializer.class)
    @NotNull
    @Size(max = 255)
    @Pattern(regexp = unipay.validator.PatternName.NAME)
    public String getName(){
        return name;
    }
 
    public void setName(String value){
        this.name = value;
    }
 
    @XmlAttribute(name="billingCycleType")
    @XmlJavaTypeAdapter(value=api.util.StringAdapter.class, type=String.class)
    @FormParam("billingCycleType")
    @StringFormat
    @JsonDeserialize(using = api.util.StringDeserializer.class)
    @NotNull
    @Size(max = 1)
    @EnumValidator(unibill.model.BillingCycleClassifier.class)
    public String getBillingCycleType(){
        return billingCycleType;
    }
 
    public void setBillingCycleType(String value){
        this.billingCycleType = value;
    }
 
    @XmlAttribute(name="amount")
    @XmlJavaTypeAdapter(value=api.util.IntegerAdapter.class, type=Integer.class)
    @FormParam("amount")
    @IntegerFormat
    @JsonDeserialize(using=api.util.NumberDeserializer.class)
    @NotNull
    @Min(0)
    public Integer getAmount(){
        return amount;
    }
 
    public void setAmount(Integer value){
        this.amount = value;
    }
 
    @XmlAttribute(name="isActive")
    @FormParam("isActive")
    @BooleanFormat
    @NotNull
    public Boolean getIsActive(){
        return isActive;
    }
 
    public void setIsActive(Boolean value){
        this.isActive = value;
    }
 
    @XmlAttribute(name="taxAmount")
    @XmlJavaTypeAdapter(value=api.util.IntegerAdapter.class, type=Integer.class)
    @FormParam("taxAmount")
    @IntegerFormat
    @JsonDeserialize(using=api.util.NumberDeserializer.class)
    @Min(0)
    public Integer getTaxAmount(){
        return taxAmount;
    }
 
    public void setTaxAmount(Integer value){
        this.taxAmount = value;
    }
 
 
 
}