package com.kryptnostic.v2.sharing.api;

import java.util.Set;
import java.util.UUID;

import com.kryptnostic.v2.constants.Names;
import com.kryptnostic.v2.sharing.models.RevocationRequest;
import com.kryptnostic.v2.sharing.models.Share;
import com.kryptnostic.v2.sharing.models.SharingRequest;
import com.kryptnostic.v2.sharing.models.VersionedObjectSearchPair;
import com.kryptnostic.v2.storage.models.VersionedObjectKey;

import retrofit.client.Response;
import retrofit.http.Body;
import retrofit.http.DELETE;
import retrofit.http.GET;
import retrofit.http.POST;
import retrofit.http.PUT;
import retrofit.http.Path;

public interface SharingApi {

    String ID      = Names.ID_FIELD;
    String VERSION = Names.VERSION_FIELD;

    String OBJECT_ID_PATH = "/id/{" + ID + "}";
    String VERSION_PATH   = "/{" + VERSION + "}";

    String SHARE       = "/share";
    String OBJECT      = "/object";
    String REVOKE      = "/revoke";
    String KEYS        = "/keys";
    String OBJECT_KEYS = "/objectKeys";

    @GET( SHARE + OBJECT )
    Iterable<Share> getIncomingShares();

    @DELETE( SHARE + OBJECT + OBJECT_ID_PATH + VERSION_PATH )
    Response removeIncomingShare( @Path( ID ) UUID objectKey, @Path( VERSION ) long version);

    @POST( SHARE + OBJECT  )
    Response share( @Body SharingRequest request );

    @DELETE( SHARE + OBJECT )
    Response revokeAccess( @Body RevocationRequest request );

    // TODO: Consider creating objects here.
    @POST( SHARE + KEYS )
    Response addSearchPairs( @Body Set<VersionedObjectSearchPair> versionedObjectSearchPairs );

    @DELETE( SHARE + KEYS )
    Response removeSearchPairs( @Body Set<VersionedObjectKey> uuids );

    // TODO: Once versions exceed values supported by JS ~2^54 we will have problems if ecmascript hasn't caught up by
    @PUT( SHARE + KEYS + OBJECT_ID_PATH + VERSION_PATH )
    Response addSearchPair( @Path( ID ) UUID objectId, @Path( VERSION ) long version, @Body byte[] objectSearchPair);

    @GET( SHARE + KEYS + OBJECT_ID_PATH + VERSION_PATH )
    byte[] getSearchPair( @Path( ID ) UUID id, @Path( VERSION ) long version);

}

@@ -656,18 +656,63 @@
  String 
-ID
+CONTROLLER     = %22/share%22;%0A    String ID       
       = 
@@ -746,16 +746,23 @@
 VERSION 
+       
 = Names.
@@ -880,43 +880,8 @@
 %22;%0A%0A
-    String SHARE       = %22/share%22;%0A
     
@@ -893,18 +893,21 @@
 g OBJECT
-  
+_PATH
     = %22/
@@ -930,105 +930,117 @@
 ing 
-REVOKE      = %22/revoke%22;%0A    String KEYS        = %22/keys%22;%0A    String OBJECT_KEYS = %22/objectKeys%22
+KEYS           = %22/keys%22;%0A    String REMOVE_INCOMING_SHARE_PATH = OBJECT_PATH + OBJECT_ID_PATH + VERSION_PATH
 ;%0A%0A 
@@ -1048,21 +1048,26 @@
   @GET( 
-SHARE
+CONTROLLER
  + OBJEC
@@ -1063,24 +1063,29 @@
 LER + OBJECT
+_PATH
  )%0A    Itera
@@ -1134,49 +1134,42 @@
 TE( 
-SHARE + OBJECT + OBJECT_ID_PATH + VERSION
+CONTROLLER + REMOVE_INCOMING_SHARE
 _PAT
@@ -1278,21 +1278,26 @@
  @POST( 
-SHARE
+CONTROLLER
  + OBJEC
@@ -1297,17 +1297,21 @@
 + OBJECT
- 
+_PATH
  )%0A    R
@@ -1371,21 +1371,26 @@
 DELETE( 
-SHARE
+CONTROLLER
  + OBJEC
@@ -1390,16 +1390,21 @@
 + OBJECT
+_PATH
  )%0A    R
@@ -1517,21 +1517,26 @@
  @POST( 
-SHARE
+CONTROLLER
  + KEYS 
@@ -1647,21 +1647,26 @@
 DELETE( 
-SHARE
+CONTROLLER
  + KEYS 
@@ -1868,21 +1868,26 @@
   @PUT( 
-SHARE
+CONTROLLER
  + KEYS 
@@ -2049,21 +2049,26 @@
   @GET( 
-SHARE
+CONTROLLER
  + KEYS 

update sharingapi