class ClientResource implements CollectionResourceProvider {

    public Promise<ResourceResponse, ResourceException> deleteInstance(Context context, String resourceId,
            DeleteRequest request) {

        String principal = PrincipalRestUtils.getPrincipalNameFromServerContext(context);

        Map<String, String> responseVal = new HashMap<String, String>();
        JsonValue response;
        try {
            String realm = request.getAdditionalParameter("realm");
            if (realm == null) {
                realm = "/";
            }
            manager.deleteIdentity(resourceId, realm);

            try {
                //delete the tokens associated with that client_id
                final TokenFilter tokenFilter = new TokenFilterBuilder().and()
                        .withAttribute(OAuthTokenField.CLIENT_ID.getField(), resourceId)
                        .withAttribute(OAuthTokenField.REALM.getField(), realm).build();
                store.deleteOnQueryAsync(tokenFilter);
            } catch (CoreTokenException e) {
                if (auditLogger.isAuditLogEnabled()) {
                    String[] obs = {"FAILED_DELETE_CLIENT", responseVal.toString()};
                    auditLogger.logErrorMessage("FAILED_DELETE_CLIENT", obs, null);
                }
                if (debug.errorEnabled()) {
                    debug.error("ClientResource :: DELETE by " + principal + ": Unable to delete client with ID, "
                            + resourceId);
                }
                throw new InternalServerErrorException("Unable to delete client", e);
            }

            responseVal.put("success", "true");
	        response = new JsonValue(responseVal);

            ResourceResponse resource = newResourceResponse("results", "1", response);
            if (auditLogger.isAuditLogEnabled()) {
                String[] obs = {"DELETED_CLIENT", response.toString()};
                auditLogger.logAccessMessage("DELETED_CLIENT", obs, null);
                if (debug.messageEnabled()) {
                    debug.error("ClientResource :: DELETE by " + principal + ": delete client with ID, " + resourceId);
                }
            }
            return newResultPromise(resource);
        } catch(IdRepoException e) {
            responseVal.put("success", "false");
            if (auditLogger.isAuditLogEnabled()) {
                String[] obs = {"FAILED_DELETE_CLIENT", responseVal.toString()};
                auditLogger.logErrorMessage("FAILED_DELETE_CLIENT", obs, null);
            }
            if (debug.errorEnabled()) {
                debug.error("ClientResource :: DELETE by " + principal +
                        ": Unable to delete client with ID, " + resourceId, e);
            }
            return new InternalServerErrorException("Unable to delete client", e).asPromise();
        } catch (SSOException e) {
            responseVal.put("success", "false");
            if (auditLogger.isAuditLogEnabled()) {
                String[] obs = {"FAILED_DELETE_CLIENT", responseVal.toString()};
                auditLogger.logErrorMessage("FAILED_DELETE_CLIENT", obs, null);
            }
            if (debug.errorEnabled()) {
                debug.error("ClientResource :: DELETE by " + principal +
                        ": Unable to delete client with ID, " + resourceId, e);
            }
            return new InternalServerErrorException("Unable to delete client", e).asPromise();
        } catch (InternalServerErrorException e) {
            responseVal.put("success", "false");
            if (auditLogger.isAuditLogEnabled()) {
                String[] obs = {"FAILED_DELETE_CLIENT", responseVal.toString()};
                auditLogger.logErrorMessage("FAILED_DELETE_CLIENT", obs, null);
            }
            if (debug.errorEnabled()) {
                debug.error("ClientResource :: DELETE by " + principal +
                        ": Unable to delete client with ID, " + resourceId, e);
            }
            return new InternalServerErrorException("Unable to delete client", e).asPromise();
        }
    }

    @Inject public  ClientResource(ClientResourceManager manager, CTSPersistentStore store, OAuth2AuditLogger auditLogger,
                          @Named("frRest") Debug debug);
    public  ClientResource(ClientResourceManager manager, CTSPersistentStore store, ServiceSchemaManager mgr,
            OAuth2AuditLogger auditLogger, Debug debug);

}