class ClientsResource {

  @Timed @ExceptionMetered
  @POST
  @Consumes(APPLICATION_JSON)
  public Response createClient(@Auth User user,
      @Valid CreateClientRequestV2 createClientRequest) {

    logger.info("User '{}' creating client '{}'.", user, createClientRequest.name());

    long clientId;
    try {
      clientId = clientDAO.createClient(createClientRequest.name(), user.getName(),
          createClientRequest.description(), new URI(createClientRequest.spiffeId()));
    } catch (DataAccessException | URISyntaxException e) {
      logger.warn("Cannot create client {}: {}", createClientRequest.name(), e);
      throw new ConflictException("Conflict creating client.");
    }

    URI uri = UriBuilder.fromResource(ClientsResource.class).path("{clientId}").build(clientId);
    Response response = Response
        .created(uri)
        .entity(clientDetailResponseFromId(clientId))
        .build();
    if (response.getStatus() == HttpStatus.SC_CREATED) {
      auditLog.recordEvent(new Event(Instant.now(), EventTag.CLIENT_CREATE, user.getName(),
          createClientRequest.name()));
    }
    return response;
  }

  @Inject public  ClientsResource(AclDAOFactory aclDAOFactory, ClientDAOFactory clientDAOFactory,
      AuditLog auditLog);
  @VisibleForTesting  ClientsResource(AclDAO aclDAO, ClientDAO clientDAO, AuditLog auditLog);

}