001package com.box.sdk;
002
003import java.util.Date;
004
005import com.box.sdk.internal.utils.JsonUtils;
006import com.eclipsesource.json.JsonObject;
007import com.eclipsesource.json.JsonValue;
008
009/**
010 * Represents a prefill tag used in BoxSignRequest. When a document contains sign related tags in the content,
011 * you can prefill them using this prefillTag by referencing the
012 * 'id' of the tag as the externalId field of the prefill tag.
013 */
014public class BoxSignRequestPrefillTag extends BoxJSONObject {
015    private String documentTagId;
016    private String textValue;
017    private Boolean checkboxValue;
018    private Date dateValue;
019
020    /**
021     * Constructs a BoxSignRequestPrefillTag with text prefill value.
022     *
023     * @param documentTagId if of the tag.
024     * @param textValue     text prefill value.
025     */
026    public BoxSignRequestPrefillTag(String documentTagId, String textValue) {
027        this.documentTagId = documentTagId;
028        this.textValue = textValue;
029    }
030
031    /**
032     * Constructs a BoxSignRequestPrefillTag with checkbox prefill value.
033     *
034     * @param documentTagId if of the tag.
035     * @param checkboxValue checkbox prefill value.
036     */
037    public BoxSignRequestPrefillTag(String documentTagId, Boolean checkboxValue) {
038        this.documentTagId = documentTagId;
039        this.checkboxValue = checkboxValue;
040    }
041
042    /**
043     * Constructs a BoxSignRequestPrefillTag with date prefill value.
044     *
045     * @param documentTagId if of the tag.
046     * @param dateValue     date prefill value.
047     */
048    public BoxSignRequestPrefillTag(String documentTagId, Date dateValue) {
049        this.documentTagId = documentTagId;
050        this.dateValue = dateValue;
051    }
052
053    /**
054     * Constructs a BoxSignRequestPrefillTag from a JSON string.
055     *
056     * @param json the JSON encoded enterprise.
057     */
058    public BoxSignRequestPrefillTag(String json) {
059        super(json);
060    }
061
062    /**
063     * Constructs an BoxSignRequestPrefillTag object using an already parsed JSON object.
064     *
065     * @param jsonObject the parsed JSON object.
066     */
067    BoxSignRequestPrefillTag(JsonObject jsonObject) {
068        super(jsonObject);
069    }
070
071    /**
072     * Gets the reference id of a particular tag added to the content
073     * of the files being used to create the sign request.
074     *
075     * @return document tag id.
076     */
077    public String getDocumentTagId() {
078        return this.documentTagId;
079    }
080
081    /**
082     * Gets the text prefill value.
083     *
084     * @return text prefill value.
085     */
086    public String getTextValue() {
087        return this.textValue;
088    }
089
090    /**
091     * Gets the checkbox prefill value.
092     *
093     * @return checkbox prefill value.
094     */
095    public Boolean getCheckboxValue() {
096        return this.checkboxValue;
097    }
098
099    /**
100     * Gets the date prefill value.
101     *
102     * @return date prefill value.
103     */
104    public Date getDateValue() {
105        return this.dateValue;
106    }
107
108    /**
109     * Gets a JSON object representing this class.
110     *
111     * @return the JSON object representing this class.
112     */
113    public JsonObject getJSONObject() {
114        JsonObject prefillTagObj = new JsonObject();
115        JsonUtils.addIfNotNull(prefillTagObj, "document_tag_id", this.documentTagId);
116        JsonUtils.addIfNotNull(prefillTagObj, "text_value", this.textValue);
117        JsonUtils.addIfNotNull(prefillTagObj, "checkbox_value", this.checkboxValue);
118        JsonUtils.addIfNotNull(prefillTagObj, "date_value", this.dateValue);
119
120        return prefillTagObj;
121    }
122
123    /**
124     * {@inheritDoc}
125     */
126    @Override
127    void parseJSONMember(JsonObject.Member member) {
128        JsonValue value = member.getValue();
129        String memberName = member.getName();
130        try {
131            if ("document_tag_id".equals(memberName)) {
132                this.documentTagId = value.asString();
133            } else if ("text_value".equals(memberName)) {
134                this.textValue = value.asString();
135            } else if ("checkbox_value".equals(memberName)) {
136                this.checkboxValue = value.asBoolean();
137            } else if ("date_value".equals(memberName)) {
138                this.dateValue = BoxDateFormat.parse(value.asString());
139            }
140        } catch (Exception e) {
141            throw new BoxDeserializationException(memberName, value.toString(), e);
142        }
143    }
144}