package com.capgemini.reports.definition.r26report;

import com.capgemini.reports.snecmaobjects.product.ProductRevision;
import com.teamcenter.soa.client.model.strong.ItemRevision;
import lombok.Getter;

@Getter
public class R26BomLine {
  private String quantity;
  private String unitOfMeasure;
  private ItemRevision receptor;
  private ItemRevision rf;
  private ProductRevision productRev;
  private ItemRevision module;
  private String effectivity;
  private Boolean consumedByProduct;
  private Boolean effectivityUnit;

  R26BomLine(final String quantity, final String unitOfMeasure, final ItemRevision receptor, final ItemRevision rf,
             final ProductRevision productRev, final ItemRevision module, final String effectivity,
             final Boolean consumedByProduct, Boolean effectivityUnit) {
    this.quantity = quantity;
    this.unitOfMeasure = unitOfMeasure;
    this.receptor = receptor;
    this.rf = rf;
    this.productRev = productRev;
    this.module = module;
    this.effectivity = effectivity;
    this.consumedByProduct = consumedByProduct;
    this.effectivityUnit = effectivityUnit;
  }

  public boolean equals(R26BomLine r26BomLine) {
    return (
      this.quantity.equals(r26BomLine.getQuantity())
        && this.unitOfMeasure.equals(r26BomLine.getUnitOfMeasure())
        && this.receptor == r26BomLine.getReceptor()
        && this.rf == r26BomLine.getRf()
        && isProductEquals(r26BomLine.getProductRev())
        && (this.module == null && r26BomLine.getModule() == null
        || (this.module != null && r26BomLine.getModule() != null
        && this.module.get_item_id().equals(r26BomLine.getModule().get_item_id())))
        && this.effectivity.contentEquals(r26BomLine.getEffectivity()));
  }

  private boolean isProductEquals(ProductRevision productRev) {
    boolean productEquals = false;
    if (this.productRev == null && productRev == null) {
      productEquals = true;
    }
    else if (this.productRev == null || productRev == null) {
      productEquals = false;
    }
    else if (this.productRev.getItemId().equals(productRev.getItemId())) {
      productEquals = true;
    }
    return productEquals;
  }

  boolean equalsExceptEffectivity(R26BomLine r26BomLine) {
    return (
      this.quantity.equals(r26BomLine.getQuantity())
        && this.unitOfMeasure.equals(r26BomLine.getUnitOfMeasure())
        && this.receptor == r26BomLine.getReceptor()
        && this.rf == r26BomLine.getRf()
        && isProductEquals(r26BomLine.getProductRev())
        && this.module == r26BomLine.getModule()
        && !this.effectivity.contentEquals(r26BomLine.getEffectivity()));
  }

  public void setEffectivity(String effectivity) {
    this.effectivity = effectivity;
  }

  Boolean isEffectivityUnit() {
    return effectivityUnit;
  }
}
