/*
 * AssignmentValue
 *
 * Created on 09.03.2009
 * Copyright (c) 2009 IVU Traffic Technologies AG
 */
package de.ivu.wahl.result.result;


import java.util.Objects;

/**
 * Value for storing assignments in a map
 *
 * @author , IVU Traffic Technologies AG
 */
public class AssignmentValue {
  private final AssignmentType assignmentType;
  private final boolean byLot;
  private final long seats;
  private final AssignmentSupplement supplement;

  AssignmentValue(Assignment assignment) {
    super();
    assignmentType = assignment.getAssignmentType();
    byLot = assignment.isByLot();
    seats = assignment.getSeats();
    supplement = assignment.getSupplement();
  }

  public AssignmentValue(AssignmentType assignmentType, boolean byLot, long seats) {
    this.assignmentType = assignmentType;
    this.byLot = byLot;
    this.seats = seats;
    this.supplement = null;
  }

  public AssignmentType getAssignmentType() {
    return assignmentType;
  }

  public boolean isByLot() {
    return byLot;
  }

  public long getSeats() {
    return seats;
  }

  public AssignmentSupplement getSupplement() {
    return supplement;
  }

  @Override
  public String toString() {
    StringBuilder builder = new StringBuilder();
    builder.append("Assign ");
    builder.append(seats);
    builder.append(" seat/s");
    if (byLot) {
      builder.append(" BY LOT");
    }
    builder.append(". Type: ");
    builder.append(assignmentType);

    return builder.toString();
  }

  public String print() {
    String tab = "\t";
    return "" + assignmentType.getKey() + tab + (byLot ? "LOT" : "") + tab + seats;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    AssignmentValue that = (AssignmentValue) o;
    return byLot == that.byLot &&
            seats == that.seats &&
            assignmentType == that.assignmentType &&
            Objects.equals(supplement, that.supplement);
  }

  @Override
  public int hashCode() {
    return Objects.hash(assignmentType, byLot, seats, supplement);
  }
}
