package be.cytomine.client.models;

/*
 * Copyright (c) 2009-2019. Authors: see NOTICE file.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import be.cytomine.client.CytomineException;
import be.cytomine.client.collections.Collection;

import java.util.List;

public class UploadedFile extends Model<UploadedFile> {

    public enum Status {

        UPLOADED (0),
        CONVERTED (1),
        DEPLOYED (2),
        ERROR_FORMAT (3),
        ERROR_CONVERSION (4),
        UNCOMPRESSED (5),
        TO_DEPLOY (6),
        TO_CONVERT (7),
        ERROR_DEPLOYMENT (8);

        private final int code;
        Status(int code) {
            this.code = code;
        }
        public int getCode() { return code; }
    }

    public UploadedFile(){}
    public UploadedFile(ImageServer server, String originalFilename, String realFilename, Long size, String ext,
                        String contentType, Collection<Project> projects, Storage storage, User user, Status status,
                        UploadedFile parent){
        this(server.getId(), originalFilename, realFilename, size, ext, contentType, projects.getListIds(), storage.getId(),
                user.getId(), status, parent != null ? parent.getId() : null);
    }
    public UploadedFile(Long idImageServer, String originalFilename, String realFilename, Long size, String ext,
                        String contentType, List idProjects, Long idStorage, Long idUser, Status status, Long idParent){
        this.set("originalFilename", originalFilename);
        this.set("filename", realFilename);
        this.set("size", size);

        this.set("ext", ext);
        this.set("contentType", contentType);

        this.set("projects", idProjects);
        this.set("storage", idStorage);

        this.set("user", idUser);
        this.set("imageServer", idImageServer);

        this.set("parent", idParent);
        if (status != null) {
            this.set("status", status.code);
        }
    }

    public UploadedFile changeStatus(Status status) throws CytomineException {
        this.set("status", status.code);
        return this.update();
    }
}

@@ -852,17 +852,16 @@
 tatus %7B%0A
-%0A
         
@@ -874,24 +874,25 @@
 ED (0),%0A
+%0A
         
 CONVERTE
@@ -887,20 +887,28 @@
     
-CONVERTED
+DETECTING_FORMAT
  (1
+0
 ),%0A 
@@ -918,19 +918,60 @@
     
-DEPLOYED
+ERROR_FORMAT (11), // 3%0A%0A        EXTRACTING_DATA
  (2
+0
 ),%0A 
@@ -987,17 +987,48 @@
 ROR_
-FORMAT
+EXTRACTION (21),%0A%0A        CONVERTING
  (3
+0
 ),%0A 
@@ -1056,37 +1056,79 @@
 ON (
-4),%0A        UNCOMPRESSED (5),
+31), // 4%0A%0A        DEPLOYING (40),%0A        ERROR_DEPLOYMENT (41), // 8%0A
 %0A   
@@ -1136,20 +1136,21 @@
     
-TO_
 DEPLOY
- (6
+ED (100
 ),%0A 
@@ -1160,51 +1160,47 @@
     
-TO_CONVERT (7),%0A        ERROR_DEPLOYMENT (8
+EXTRACTED (102),%0A        CONVERTED (104
 );%0A%0A

Update uploaded file status enumeration