package api.account;

import api.ExecuteResult;
import dbcommons.exception.DatabaseException;
import org.jetbrains.annotations.NotNull;
import replicationAnnotations.AccessLevel;
import replicationAnnotations.OuterWorldAPI;

/**
 * Provides access to hash algorithms, and allows to create/modify accounts using hashes instead of passwords.
 *
 * @author andrey.kuprishov
 */
@OuterWorldAPI
public interface AccountAndHashAPIInterface {
  /**
   * Gets all registered algorithms.
   * 
   * @throws dbcommons.exception.DatabaseException when DB error occured
   */
  @NotNull
  HashAlgoInfo[] getAlgorithms() throws DatabaseException;

  /**
   * Adds hash algorithm and returns its id or returns id of already existing algorithm.
   * @throws dbcommons.exception.DatabaseException when DB error occured
   */
  long addAlgorithm(@NotNull String name, boolean saltThenPwd, @NotNull String charsetName) throws DatabaseException;

  /**
   * Possibility to create accound without submitting password (using already prepared hash).
   */
  @NotNull
  ExecuteResult createAccountWithHashAndSalt(@NotNull String userName,
                                       @NotNull String hash, @NotNull String salt, long hashAlgorithmId,
                                       @NotNull AccessLevel acccesLevel, @NotNull AccountStatus status);

  /**
   * For those who doesn't want to provide salt.
   */
  @NotNull
  ExecuteResult createAccountWithHash(@NotNull String userName,
                                       @NotNull String hash, @NotNull String operatorTag,
                                       @NotNull AccessLevel acccesLevel, @NotNull AccountStatus status);

  @NotNull
  ExecuteResult modifyAccountHashAndSalt(@NotNull String userName, @NotNull String newHash, @NotNull String salt, long hashAlgorithmId);

  @NotNull
  ExecuteResult modifyAccountHash(@NotNull String userName, @NotNull String newHash, @NotNull String operatorTag);

  @NotNull
  ExecuteResult registerOperatorAlgorithm(@NotNull String operatorTag, @NotNull String salt, long hashAlgorithmId);
}
