package com.kryptnostic.directory.v1.http;

import java.util.UUID;

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

import com.google.common.base.Optional;
import com.kryptnostic.directory.v1.ContactDiscoveryRequest;
import com.kryptnostic.directory.v1.ContactDiscoveryResponse;
import com.kryptnostic.directory.v1.exception.MailException;
import com.kryptnostic.directory.v1.exception.RealmMismatchException;
import com.kryptnostic.directory.v1.exception.ReservationTakenException;
import com.kryptnostic.directory.v1.exception.UserUpdateException;
import com.kryptnostic.directory.v1.principal.User;
import com.kryptnostic.kodex.v1.exceptions.types.BadRequestException;

/**
 * RESTful API for adding, modifying, and removing users on the Kryptnostic platform.
 *
 * @author Nick Hewitt
 * @author Matthew Tamayo-Rios &lt;matthew@kryptnostic.com&gt;
 *
 */
public interface UserDirectoryApi {
    public static final String CONTROLLER          = "/directory";
    public static final String ID                  = "id";
    public static final String EMAIL               = "email";
    public static final String REALM               = "realm";
    public static final String USERNAME            = "username";
    public static final String DISCOVERY           = "/discovery";
    public static final String USERS               = "/users";
    public static final String RESET               = "/reset";
    public static final String ID_PATH             = "/{" + ID + "}";
    public static final String ID_WITH_DOT         = "/{" + ID + ":.+}";
    public static final String REALM_PATH          = "/{" + REALM + "}";
    public static final String USERNAME_PATH       = "/{" + USERNAME + "}";
    public static final String EMAIL_PATH          = "/" + EMAIL + "/{" + EMAIL + "}";   // +EMAIL needed to
                                                                                          // disambiguate from get user
    public static final String EMAIL_PATH_WITH_DOT = "/" + EMAIL + "/{" + EMAIL + ":.+}";

    /**
     * Get the account details for a given user.
     *
     * @param userId String form of reserved {@link UUID}
     * @return The user
     */
    @GET( CONTROLLER + USERS + ID_PATH )
    Optional<User> getUser( @Path( ID ) UUID userId ); // developer

    /**
     * Delete a specific user, removing it from the directory.
     *
     * @param userId the user id of the user to be deleted.
     * @return the UUID of the user deleted if any.
     * @throws RealmMismatchException
     */
    @DELETE( CONTROLLER + USERS + ID_PATH )
    Optional<UUID> deleteUser( @Path( ID ) UUID userId ) throws RealmMismatchException; // developer

    /**
     * Allows resolving an e-mail to a UUID. This is an open API.
     *
     * @param email
     * @return
     */
    @GET( CONTROLLER + USERS + EMAIL_PATH )
    Optional<UUID> resolve( @Path( EMAIL ) String email );

    /**
     * This API resets the users authenticator. It does not impact key information.
     *
     * @param userKey
     * @param newPassword
     * @return
     * @throws UserUpdateException
     * @throws ReservationTakenException
     * @throws BadRequestException
     * @throws MailException
     */
    @PUT( CONTROLLER + USERS + ID_PATH )
    Optional<UUID> resetPassword( @Path( ID ) UUID userKey, @Body String newPassword ) throws UserUpdateException,
            ReservationTakenException, BadRequestException, MailException;

    /**
     * Allows discovering contacts by e-mail or name search.
     * 
     * @param request E-mail and name search terms.
     * @return Scored soundex, metaphone, and exact match search results on name and e-mail as specified in the request.
     */
    @POST( CONTROLLER + DISCOVERY )
    ContactDiscoveryResponse discover( ContactDiscoveryRequest request );
}

@@ -37,16 +37,38 @@
 .http;%0A%0A
+import java.util.Set;%0A
 import j
@@ -82,16 +82,16 @@
 l.UUID;%0A
-
 %0Aimport 
@@ -1403,24 +1403,86 @@
 discovery%22;%0A
+    public static final String USER                = %22/user%22;%0A
     public s
@@ -2380,33 +2380,32 @@
 ONTROLLER + USER
-S
  + ID_PATH )%0A   
@@ -2462,32 +2462,292 @@
 ; // developer%0A%0A
+    /**%0A     * Get the account details for a given user.%0A     *%0A     * @param userId String form of reserved %7B@link UUID%7D%0A     * @return The user%0A     */%0A    @GET( CONTROLLER + USERS )%0A    Optional%3CSet%3CUser%3E%3E getUsers( @Body Set%3CUUID%3E userIds ); // developer%0A%0A
     /**%0A     * D
@@ -2988,33 +2988,32 @@
 ONTROLLER + USER
-S
  + ID_PATH )%0A   
@@ -3262,17 +3262,16 @@
 R + USER
-S
  + EMAIL
@@ -3675,17 +3675,16 @@
 R + USER
-S
  + ID_PA
@@ -3948,23 +3948,22 @@
 search.%0A
+
      *
- 
 %0A     * 

add bulk user loading to userDirectoryApi