package de.ivu.elect.jee.performance;

import java.io.Serializable;

public class ViewAccessTarget implements Serializable {

  public static final String SESSION_ID_OHNE = "<ohne>";

  private final ViewType type;

  private final ViewAccessType accessType;
  private final PhaseIdEnum phaseId;

  private final String sessionId;
  private final String viewId;

  public ViewAccessTarget(ViewType type, ViewAccessType accessType, PhaseIdEnum phaseId, String sessionId, String viewId) {
    this.type = type;
    this.accessType = accessType;
    this.phaseId = phaseId;
    this.sessionId = sessionId;
    this.viewId = viewId;
  }

  public ViewAccessType getAccessType() {
    return accessType;
  }

  public ViewType getType() {
    return type;
  }

  public String getSessionId() {
    return sessionId;
  }

  public PhaseIdEnum getPhaseId() {
    return phaseId;
  }

  public String getViewId() {
    return viewId;
  }

  @Override
  public String toString() {
    return "ViewAccessTarget{" +
        "type=" + type +
        ", accessType=" + accessType +
        ", phaseId=" + phaseId +
        ", sessionId='" + sessionId + '\'' +
        ", viewId='" + viewId + '\'' +
        '}';
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (!(o instanceof ViewAccessTarget)) return false;

    ViewAccessTarget that = (ViewAccessTarget) o;

    if (type != that.type) return false;
    if (accessType != that.accessType) return false;
    if (phaseId != that.phaseId) return false;
    if (!sessionId.equals(that.sessionId)) return false;
    return viewId.equals(that.viewId);
  }

  @Override
  public int hashCode() {
    int result = type.hashCode();
    result = 31 * result + accessType.hashCode();
    result = 31 * result + phaseId.hashCode();
    result = 31 * result + sessionId.hashCode();
    result = 31 * result + viewId.hashCode();
    return result;
  }

  protected ViewAccessTarget(ViewAccessTarget viewAccessTarget) {
    this(viewAccessTarget.getType(), viewAccessTarget.getAccessType(), viewAccessTarget.getPhaseId(), viewAccessTarget.getSessionId(),
        viewAccessTarget.getViewId());
  }

  public static ViewAccessTarget copyNewSessionId(ViewAccessTarget viewAccessTarget, String newSessionId) {
    return new ViewAccessTarget(viewAccessTarget.getType(), viewAccessTarget.getAccessType(), viewAccessTarget.getPhaseId(), newSessionId,
        viewAccessTarget.getViewId());
  }

  public static ViewAccessTarget copyNewAccessType(ViewAccessTarget viewAccessTarget, ViewAccessType newViewAccessType) {
    return new ViewAccessTarget(viewAccessTarget.getType(), newViewAccessType, viewAccessTarget.getPhaseId(), viewAccessTarget.getSessionId(),
        viewAccessTarget.getViewId());
  }

}
