001package com.box.sdk;
002
003import com.eclipsesource.json.JsonObject;
004
005/**
006 * Represents a Box File to be included in a sign request.
007 */
008public class BoxSignRequestFile {
009    private String fileId;
010    private String fileVersionId;
011
012    /**
013     * Constructs a BoxSignRequestFile with specific file version to be used during sign request creation.
014     *
015     * @param fileId        id of the file.
016     * @param fileVersionId id of the file versionm.
017     */
018    public BoxSignRequestFile(String fileId, String fileVersionId) {
019        this.fileId = fileId;
020        this.fileVersionId = fileVersionId;
021    }
022
023    /**
024     * Constructs a BoxSignRequestFile to be used during sign request creation.
025     *
026     * @param fileId id of the file.
027     */
028    public BoxSignRequestFile(String fileId) {
029        this.fileId = fileId;
030    }
031
032    static BoxSignRequestFile fromFile(BoxFile.Info sourceFile) {
033        BoxSignRequestFile file = new BoxSignRequestFile(sourceFile.getID());
034        if (sourceFile.getVersion() != null) {
035            file.setFileVersionId(sourceFile.getVersionNumber());
036        }
037
038        return file;
039    }
040
041    /**
042     * Gets the file id of the file.
043     *
044     * @return file id of the file.
045     */
046    public String getFileId() {
047        return this.fileId;
048    }
049
050    /**
051     * Sets the file id.
052     *
053     * @param fileId of the file.
054     * @return this BoxSignRequestFile object for chaining.
055     */
056    public BoxSignRequestFile setFileId(String fileId) {
057        this.fileId = fileId;
058        return this;
059    }
060
061    /**
062     * Gets the file version id of the file.
063     *
064     * @return file version id of the file.
065     */
066    public String getFileVersionId() {
067        return this.fileVersionId;
068    }
069
070    /**
071     * Sets the file version id.
072     *
073     * @param fileVersionId of the file.
074     * @return this BoxSignRequestFile object for chaining.
075     */
076    public BoxSignRequestFile setFileVersionId(String fileVersionId) {
077        this.fileVersionId = fileVersionId;
078        return this;
079    }
080
081    /**
082     * Gets a JSON object representing this class.
083     *
084     * @return the JSON object representing this class.
085     */
086    public JsonObject getJSONObject() {
087        JsonObject fileJSON = new JsonObject()
088            .add("id", this.fileId)
089            .add("type", "file");
090
091        if (this.fileVersionId != null) {
092            JsonObject fileVersionJSON = new JsonObject();
093            fileVersionJSON.add("id", this.fileVersionId);
094            fileVersionJSON.add("type", "file_version");
095            fileJSON.add("file_version", fileVersionJSON);
096        }
097
098        return fileJSON;
099    }
100}