001package com.box.sdk;
002
003import com.eclipsesource.json.JsonObject;
004import com.eclipsesource.json.JsonValue;
005
006/**
007 * Represents the download status of a zip file.
008 */
009public class BoxZipDownloadStatus extends BoxJSONObject {
010    private int totalFileCount;
011    private int downloadFileCount;
012    private int skippedFileCount;
013    private int skippedFolderCount;
014    private State state;
015
016    /**
017     * Constructs a BoxZipDownloadStatus with default settings.
018     */
019    public BoxZipDownloadStatus() {
020    }
021
022    /**
023     * Constructs a BoxZipDownloadStatus from a JSON string.
024     *
025     * @param json the JSON encoded enterprise.
026     */
027    public BoxZipDownloadStatus(String json) {
028        super(json);
029    }
030
031    BoxZipDownloadStatus(JsonObject jsonObject) {
032        super(jsonObject);
033    }
034
035    /**
036     * Gets the total number of files in the zip.
037     *
038     * @return the total number of files in the zip.
039     */
040    public int getTotalFileCount() {
041        return this.totalFileCount;
042    }
043
044    /**
045     * Gets the number of files in the zip that were downloaded.
046     *
047     * @return the number of files in the zip that were downloaded.
048     */
049    public int getDownloadFileCount() {
050        return this.downloadFileCount;
051    }
052
053    /**
054     * Gets the number of files in the zip that were skipped when downloading.
055     *
056     * @return the number of files in the zip that were skipped when downloading.
057     */
058    public int getSkippedFileCount() {
059        return this.skippedFileCount;
060    }
061
062    /**
063     * Gets the number of folders in the zip that were skipped when downloading.
064     *
065     * @return the number of folder in the zip that were skipped when downloading.
066     */
067    public int getSkippedFolderCount() {
068        return this.skippedFolderCount;
069    }
070
071    /**
072     * Gets the state of the download for the zip file.
073     *
074     * @return the state of the download for the zip file
075     */
076    public State getState() {
077        return this.state;
078    }
079
080    @Override
081    void parseJSONMember(JsonObject.Member member) {
082        JsonValue value = member.getValue();
083        String memberName = member.getName();
084        if (memberName.equals("total_file_count")) {
085            this.totalFileCount = value.asInt();
086        } else if (memberName.equals("download_file_count")) {
087            this.downloadFileCount = value.asInt();
088        } else if (memberName.equals("skipped_file_count")) {
089            this.skippedFileCount = value.asInt();
090        } else if (memberName.equals("skipped_folder_count")) {
091            this.skippedFolderCount = value.asInt();
092        } else if (memberName.equals("state")) {
093            this.state = State.fromJSONValue(value.asString());
094        }
095    }
096
097    /**
098     * Enumerates the possible download states of a zip.
099     */
100    public enum State {
101        /**
102         * Succeeded in downloading.
103         */
104        SUCCEEDED("succeeded"),
105
106        /**
107         * Downloading in progress.
108         */
109        IN_PROGRESS("in_progress"),
110
111        /**
112         * Failed when downloading.
113         */
114        FAILED("failed");
115
116        private final String jsonValue;
117
118        State(String jsonValue) {
119            this.jsonValue = jsonValue;
120        }
121
122        static State fromJSONValue(String jsonValue) {
123            return State.valueOf(jsonValue.toUpperCase());
124        }
125
126        String toJSONValue() {
127            return this.jsonValue;
128        }
129    }
130}