package org.whispersystems.textsecuregcm.controllers;

import com.codahale.metrics.annotation.Timed;
import org.whispersystems.textsecuregcm.auth.ExternalServiceCredentialGenerator;
import org.whispersystems.textsecuregcm.auth.ExternalServiceCredentials;
import org.whispersystems.textsecuregcm.storage.Account;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import io.dropwizard.auth.Auth;

@Path("/v1/storage")
public class SecureStorageController {

  private final ExternalServiceCredentialGenerator storageServiceCredentialGenerator;

  public SecureStorageController(ExternalServiceCredentialGenerator storageServiceCredentialGenerator) {
    this.storageServiceCredentialGenerator = storageServiceCredentialGenerator;
  }

  @Timed
  @GET
  @Path("/auth")
  @Produces(MediaType.APPLICATION_JSON)
  public ExternalServiceCredentials getAuth(@Auth Account account) {
    return storageServiceCredentialGenerator.generateFor(account.getUuid().toString());
  }
}
