package com.cloudmine.api.rest.response;

import com.cloudmine.api.rest.response.code.ObjectModificationCode;
import org.apache.http.HttpResponse;

import java.util.ArrayList;
import java.util.List;

/**
 * Response returned whenever objects are added, updated, or deleted on the CloudMine platform.
 * Lets you check whether a specific object was updated/created/deleted/modified
 * <br>Copyright CloudMine LLC. All rights reserved<br> See LICENSE file included with SDK for details.
 */
public class ObjectModificationResponse extends SuccessErrorResponse<ObjectModificationCode>{

    public static final ResponseConstructor<ObjectModificationResponse> CONSTRUCTOR = new ResponseConstructor<ObjectModificationResponse>() {
        @Override
        public ObjectModificationResponse construct(HttpResponse response) {
            return new ObjectModificationResponse(response);
        }
    };

    /**
     * Instantiate a new ObjectModificationResponse. You probably should not be calling this yourself
     * @param response a response to an add/update/delete request
     */
    public ObjectModificationResponse(HttpResponse response) {
        super(response);
    }

    /**
     * Internal use only
     * @param messageBody
     * @param statusCode
     */
    public ObjectModificationResponse(String messageBody, int statusCode) {
        super(messageBody, statusCode);
    }

    @Override
    public ObjectModificationCode getResponseCode() {
        return ObjectModificationCode.codeForStatus(getStatusCode());
    }

    /**
     * Check whether a specific object already existed and had its values updated
     * @param objectId the object objectId
     * @return true if the object already existed and was updated
     */
    public boolean wasUpdated(String objectId) {
        return ResponseValue.UPDATED.equals(getKeyResponse(objectId));
    }

    /**
     * Check whether a specific object was created
     * @param objectId the object objectId
     * @return true if the object associated with the given objectId was inserted
     */
    public boolean wasCreated(String objectId) {
        return ResponseValue.CREATED.equals(getKeyResponse(objectId));
    }

    /**
     * Check whether a specific object was deleted
     * @param objectId the object objectId
     * @return true if the object associated with the given objectId was deleted
     */
    public boolean wasDeleted(String objectId) {
        return ResponseValue.DELETED.equals(getKeyResponse(objectId));
    }

    /**
     * Check whether a specific object was created, deleted, or updated
     * @param objectId the object objectId
     * @return true if the object associated with the given objectId was created, updated, or deleted
     */
    public boolean wasModified(String objectId) {
        return !ResponseValue.MISSING.equals(getKeyResponse(objectId));
    }

    /**
     * Gets the object ids of all the objects that were deleted
     * @return the object ids of all the objects that were deleted
     */
    public List<String> getDeletedObjectIds() {
        List<String> deletedObjectIds = new ArrayList<String>();
        for(String objectId : getSuccessMap().keySet()) {
            if(wasDeleted(objectId)) {
                deletedObjectIds.add(objectId);
            }
        }
        return deletedObjectIds;
    }

    /**
     * Get the ResponseValue for the object associated with the given objectId
     * @param objectId the object objectId
     * @return the ResponseValue for the object associated with the given objectId. If the object does not exist, ResponseValue.MISSING is returned.
     */
    public ResponseValue getKeyResponse(String objectId) {
        Object keyedValue = getSuccessMap().get(objectId);
        if(keyedValue == null)
            return ResponseValue.MISSING;
        return ResponseValue.getValue(keyedValue.toString());
    }

}

@@ -162,40 +162,9 @@
 til.
-ArrayList;%0Aimport java.util.List
+*
 ;%0A%0A/
@@ -3131,27 +3131,17 @@
  get
-SuccessMap().keySet
+ObjectIds
 ()) 
@@ -3245,32 +3245,32 @@
     %7D%0A        %7D%0A
-
         return d
@@ -3285,32 +3285,1349 @@
 jectIds;%0A    %7D%0A%0A
+    /**%0A     * Gets the object ids of all the objects that were updated%0A     * @return%0A     */%0A    public List%3CString%3E getUpdatedObjectIds() %7B%0A        List%3CString%3E updatedObjectIds = new ArrayList%3CString%3E();%0A        for(String objectId : getObjectIds()) %7B%0A            if(wasUpdated(objectId)) %7B%0A                updatedObjectIds.add(objectId);%0A            %7D%0A        %7D%0A        return updatedObjectIds;%0A    %7D%0A%0A    /**%0A     * Gets the object ids of all the objects that were created%0A     * @return%0A     */%0A    public List%3CString%3E getCreatedObjectIds() %7B%0A        List%3CString%3E createdObjectIds = new ArrayList%3CString%3E();%0A        for(String objectId : getObjectIds()) %7B%0A            if(wasCreated(objectId)) %7B%0A                createdObjectIds.add(objectId);%0A            %7D%0A        %7D%0A        return createdObjectIds;%0A    %7D%0A%0A    /**%0A     * Get a Map from the ObjectIds that have been modified, to how they were modified%0A     * @return%0A     */%0A    public Map%3CString, ResponseValue%3E getModifiedMap() %7B%0A        Map%3CString, ResponseValue%3E statusMap = new HashMap%3CString, ResponseValue%3E();%0A        for(String objectId : getObjectIds()) %7B%0A            statusMap.put(objectId, getKeyResponse(objectId));%0A        %7D%0A        return statusMap;%0A    %7D%0A%0A    private Set%3CString%3E getObjectIds() %7B%0A        return getSuccessMap().keySet();%0A    %7D%0A%0A
     /**%0A     * G

Update ObjectModificationResponse