package api.unicore.component;
 
import static api.util.ComponentConstants.BOOLEAN_NULL;
import static api.util.ComponentConstants.BOOLEAN_NULL_CODE;
import static api.util.ComponentConstants.DATE_NULL;
import static api.util.ComponentConstants.DATE_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 com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL;
 
import api.UnoComponent;
import api.unicore.component_manual.KeyRegistry;
import api.util.BooleanFormat;
import api.util.DateFormat;
import api.util.LongFormat;
import api.util.StringFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import iapp.services.ServerObject;
import iapp.util.audit.AuditHelper;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import jakarta.ws.rs.DefaultValue;
import jakarta.ws.rs.FormParam;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlAttribute;
import jakarta.xml.bind.annotation.XmlSeeAlso;
import jakarta.xml.bind.annotation.XmlType;
import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.util.Date;
import unipay.fields_manual.Fields;
import unipay.validator.CustomValidator;
import unipay.validator.EnumValidator;
 
/**
 * @author CodeGen [Dmitriy Druppov]
 * @company UnitedThinkers
 * @since 2022/01/28
 */
 
@JsonInclude(NON_NULL)
@XmlType(propOrder={"id", "decryptionKeyCode", "description", "algorithm", "content", "keyStorage", "expirationDate", "attribute", "isActive"})
@JsonPropertyOrder({"id", "decryptionKeyCode", "description", "algorithm", "content", "keyStorage", "expirationDate", "attribute", "isActive"})
@XmlAccessorType(XmlAccessType.NONE)
@XmlSeeAlso(KeyRegistry.class)
@CustomValidator
public abstract class AbstractKeyRegistry extends UnoComponent<unicharge.model.KeyRegistry> {
 
    @FormParam("id")
    @LongFormat
    @DefaultValue(LONG_NULL_CODE)
    protected Long id;
 
    @FormParam("decryptionKeyCode")
    @StringFormat
    @DefaultValue(STRING_NULL_CODE)
    protected String decryptionKeyCode;
 
    @FormParam("description")
    @StringFormat
    @DefaultValue(STRING_NULL_CODE)
    protected String description;
 
    @FormParam("algorithm")
    @StringFormat
    protected String algorithm;
 
    @FormParam("content")
    @StringFormat
    @DefaultValue(STRING_NULL_CODE)
    protected String content;
 
    @FormParam("keyStorage")
    @StringFormat
    @DefaultValue(STRING_NULL_CODE)
    protected String keyStorage;
 
    @FormParam("expirationDate")
    @DateFormat
    @DefaultValue(DATE_NULL_CODE)
    protected Date expirationDate;
 
    @FormParam("attribute")
    @StringFormat
    @DefaultValue(STRING_NULL_CODE)
    protected String attribute;
 
    @FormParam("isActive")
    @BooleanFormat
    @DefaultValue(BOOLEAN_NULL_CODE)
    protected Boolean isActive;
 
 
    public AbstractKeyRegistry(){
        super();
        applyDefaults();
    }
 
    public AbstractKeyRegistry(unicharge.model.KeyRegistry object){
        super(object);
    }
 
 
    private void applyDefaults() {
        if (!isProxyObject()) {
            id = LONG_NULL;
            decryptionKeyCode = STRING_NULL;
            description = STRING_NULL;
            content = STRING_NULL;
            keyStorage = STRING_NULL;
            expirationDate = DATE_NULL;
            attribute = STRING_NULL;
            isActive = BOOLEAN_NULL;
        }
        algorithm = unicharge.model.AlgorithmClassifier.IDTECH_P2PE_TDES.getValue();
    }
 
    @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("key: {");
        sb.append("id: ");
        sb.append(id);
        sb.append(',').append(' ');
        sb.append("decryptionKeyCode: ");
        sb.append(decryptionKeyCode);
        sb.append(',').append(' ');
        sb.append("description: ");
        sb.append(description);
        sb.append(',').append(' ');
        sb.append("algorithm: ");
        sb.append(algorithm);
        sb.append(',').append(' ');
        sb.append("content: ");
        sb.append(content);
        sb.append(',').append(' ');
        sb.append("keyStorage: ");
        sb.append(keyStorage);
        sb.append(',').append(' ');
        sb.append("expirationDate: ");
        sb.append(expirationDate);
        sb.append(',').append(' ');
        sb.append("attribute: ");
        sb.append(attribute);
        sb.append(',').append(' ');
        sb.append("isActive: ");
        sb.append(isActive);
        sb.append('}');
        return sb.toString();
    }
 
 
    @XmlAttribute(name="id")
    @XmlJavaTypeAdapter(api.util.LongAdapter.class)
    @FormParam("id")
    @LongFormat
    @JsonDeserialize(using=api.util.NumberDeserializer.class)
    public Long getId(){
        return id;
    }
 
 
    @XmlAttribute(name="decryptionKeyCode")
    @XmlJavaTypeAdapter(api.util.StringAdapter.class)
    @FormParam("decryptionKeyCode")
    @StringFormat
    @JsonDeserialize(using = api.util.StringDeserializer.class)
    @NotNull
    @Size(min = 1, max = 25)
    @Pattern(regexp = unipay.validator.PatternName.CODE)
    public String getDecryptionKeyCode(){
        return decryptionKeyCode;
    }
 
    public void setDecryptionKeyCode(String value){
        this.decryptionKeyCode = value;
    }
 
    @XmlAttribute(name="description")
    @XmlJavaTypeAdapter(api.util.StringAdapter.class)
    @FormParam("description")
    @StringFormat
    @JsonDeserialize(using = api.util.StringDeserializer.class)
    @Size(max = 510)
    @Pattern(regexp = unipay.validator.PatternName.TEXT)
    public String getDescription(){
        return description;
    }
 
    public void setDescription(String value){
        this.description = value;
    }
 
    @XmlAttribute(name="algorithm")
    @XmlJavaTypeAdapter(api.util.StringAdapter.class)
    @FormParam("algorithm")
    @StringFormat
    @JsonDeserialize(using = api.util.StringDeserializer.class)
    @EnumValidator(unicharge.model.AlgorithmClassifier.class)
    public String getAlgorithm(){
        return algorithm;
    }
 
    public void setAlgorithm(String value){
        this.algorithm = value;
    }
 
    @XmlAttribute(name="content")
    @XmlJavaTypeAdapter(api.util.StringAdapter.class)
    @FormParam("content")
    @StringFormat
    @JsonDeserialize(using = api.util.StringDeserializer.class)
    @Size(min = 1, max = 2500)
    @Pattern(regexp = unipay.validator.PatternName.TEXT)
    public String getContent(){
        return content;
    }
 
    public void setContent(String value){
        this.content = value;
    }
 
    @XmlAttribute(name="keyStorage")
    @XmlJavaTypeAdapter(api.util.StringAdapter.class)
    @FormParam("keyStorage")
    @StringFormat
    @JsonDeserialize(using = api.util.StringDeserializer.class)
    @EnumValidator(unicharge.model.KeyStorageClassifier.class)
    public String getKeyStorage(){
        return keyStorage;
    }
 
    public void setKeyStorage(String value){
        this.keyStorage = value;
    }
 
    @XmlAttribute(name="expirationDate")
    @FormParam("expirationDate")
    @DateFormat
    @JsonDeserialize(using=api.util.DateDeserializer.class)
    public Date getExpirationDate(){
        return expirationDate;
    }
 
    public void setExpirationDate(Date value){
        this.expirationDate = value;
    }
 
    @XmlAttribute(name="attribute")
    @XmlJavaTypeAdapter(api.util.StringAdapter.class)
    @FormParam("attribute")
    @StringFormat
    @JsonDeserialize(using = api.util.StringDeserializer.class)
    @Size(max = 512)
    public String getAttribute(){
        return attribute;
    }
 
    public void setAttribute(String value){
        this.attribute = value;
    }
 
    @XmlAttribute(name="isActive")
    @FormParam("isActive")
    @BooleanFormat
    public Boolean getIsActive(){
        return isActive;
    }
 
    public void setIsActive(Boolean value){
        this.isActive = value;
    }
 
 
    public void audit(AuditHelper helper, ServerObject object) {
        unicharge.model.KeyRegistry s_object = (unicharge.model.KeyRegistry) object;
        helper.audit("id", id, s_object.getId());
        helper.audit("decryptionKeyCode", decryptionKeyCode, s_object.getName());
        helper.audit("description", description, s_object.getDescription());
        helper.audit("algorithm", STRING_NULL.equals(algorithm) ? null : unicharge.model.AlgorithmClassifier.fromString(Fields.Management.KeyRegistry.Algorithm, algorithm), s_object.getAlgorithmCl() == null ? null : s_object.getAlgorithmCl().getValue());
        helper.audit("content", content, s_object.getContent());
        helper.audit("keyStorage", STRING_NULL.equals(keyStorage) ? null : unicharge.model.KeyStorageClassifier.fromString(Fields.Management.KeyRegistry.KeyStorage, keyStorage), s_object.getKeyStorageCl() == null ? null : s_object.getKeyStorageCl().getValue());
        helper.audit("expirationDate", expirationDate, s_object.getExpirationDate());
        helper.audit("attribute", attribute, s_object.getAttribute());
        helper.audit("isActive", isActive, s_object.getIsActive());
 
    }
 
    public static String objectTypeCode(){
        return "keys/idtech";
    }
 
}