package api.account;

import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.NotNull;
import replicationAnnotations.OuterWorldAPI;

import java.io.Serializable;

/**
 * Hashing algorithm presentation via api.
 *
 * @author andrey.kuprishov
 */
@OuterWorldAPI
public class HashAlgoInfo implements Serializable {
  private static final long serialVersionUID = 5830066028625054627L;
  /**
   * Id of algorithm.
   */
  private long id = -1L;
  /**
   * Name of algorithm (e.g. SHA-1 or MD%, name is used to create message digest object).
   */
  @NotNull
  private String name = StringUtils.EMPTY;
  /**
   * If true then we calculate hash(salt + password), if false - hash(password + salt).
   */
  private boolean saltThenPwd = false;
  /**
   * Charset name used to provide raw bytes to hash method. E.g. 'UTF-8'.
   */
  @NotNull
  private String charsetName = StringUtils.EMPTY;

  public HashAlgoInfo() {
  }

  public HashAlgoInfo(long id, @NotNull String name, boolean saltThenPwd, @NotNull String charsetName) {
    this.id = id;
    this.name = name;
    this.saltThenPwd = saltThenPwd;
    this.charsetName = charsetName;
  }

  @NotNull
  public String getCharsetName() {
    return charsetName;
  }

  public long getId() {
    return id;
  }

  @NotNull
  public String getName() {
    return name;
  }

  public boolean isSaltThenPwd() {
    return saltThenPwd;
  }

  public void setCharsetName(@NotNull String charsetName) {
    this.charsetName = charsetName;
  }

  public void setId(long id) {
    this.id = id;
  }

  public void setName(@NotNull String name) {
    this.name = name;
  }

  public void setSaltThenPwd(boolean saltThenPwd) {
    this.saltThenPwd = saltThenPwd;
  }
}
