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