package com.oguerreiro.resilient.service.criteria;

import java.util.Objects;
import java.util.Optional;

import org.springdoc.core.annotations.ParameterObject;

import tech.jhipster.service.filter.Filter;
import tech.jhipster.service.filter.LongFilter;
import tech.jhipster.service.filter.StringFilter;

/**
 * Criteria class for the {@link com.oguerreiro.resilient.domain.Unit}
 * entity. This class is used in
 * {@link com.oguerreiro.resilient.web.rest.UnitResource} to receive all
 * the possible filtering options from the Http GET request parameters. For
 * example the following could be a valid request:
 * {@code /unit?id.greaterThan=5&attr1.contains=something&attr2.specified=false}
 * As Spring is unable to properly convert the types, unless specific
 * {@link Filter} class are used, we need to use fix type specific filters.
 */
@ParameterObject
public class UnitCriteria extends AbstractCriteria {
  private static final long serialVersionUID = 1L;

  private LongFilter id;

  private StringFilter code;

  private StringFilter name;

  private StringFilter symbol;

  private StringFilter description;

  private LongFilter unitTypeId;

  public UnitCriteria() {
  }

  public UnitCriteria(UnitCriteria other) {
    super(other);

    this.id = other.optionalId().map(LongFilter::copy).orElse(null);
    this.code = other.optionalCode().map(StringFilter::copy).orElse(null);
    this.name = other.optionalName().map(StringFilter::copy).orElse(null);
    this.symbol = other.optionalSymbol().map(StringFilter::copy).orElse(null);
    this.description = other.optionalDescription().map(StringFilter::copy).orElse(null);
    this.unitTypeId = other.optionalUnitTypeId().map(LongFilter::copy).orElse(null);
  }

  @Override
  public UnitCriteria copy() {
    return new UnitCriteria(this);
  }

  public LongFilter getId() {
    return id;
  }

  public Optional<LongFilter> optionalId() {
    return Optional.ofNullable(id);
  }

  public LongFilter id() {
    if (id == null) {
      setId(new LongFilter());
    }
    return id;
  }

  public void setId(LongFilter id) {
    this.id = id;
  }

  public StringFilter getCode() {
    return code;
  }

  public Optional<StringFilter> optionalCode() {
    return Optional.ofNullable(code);
  }

  public StringFilter code() {
    if (code == null) {
      setCode(new StringFilter());
    }
    return code;
  }

  public void setCode(StringFilter code) {
    this.code = code;
  }

  public StringFilter getName() {
    return name;
  }

  public Optional<StringFilter> optionalName() {
    return Optional.ofNullable(name);
  }

  public StringFilter name() {
    if (name == null) {
      setName(new StringFilter());
    }
    return name;
  }

  public void setName(StringFilter name) {
    this.name = name;
  }

  public StringFilter getDescription() {
    return description;
  }

  public StringFilter getSymbol() {
    return symbol;
  }

  public Optional<StringFilter> optionalSymbol() {
    return Optional.ofNullable(symbol);
  }

  public StringFilter symbol() {
    if (symbol == null) {
      setSymbol(new StringFilter());
    }
    return symbol;
  }

  public void setSymbol(StringFilter symbol) {
    this.symbol = symbol;
  }

  public Optional<StringFilter> optionalDescription() {
    return Optional.ofNullable(description);
  }

  public StringFilter description() {
    if (description == null) {
      setDescription(new StringFilter());
    }
    return description;
  }

  public void setDescription(StringFilter description) {
    this.description = description;
  }

  public LongFilter getUnitTypeId() {
    return unitTypeId;
  }

  public Optional<LongFilter> optionalUnitTypeId() {
    return Optional.ofNullable(unitTypeId);
  }

  public LongFilter unitTypeId() {
    if (unitTypeId == null) {
      setUnitTypeId(new LongFilter());
    }
    return unitTypeId;
  }

  public void setUnitTypeId(LongFilter unitTypeId) {
    this.unitTypeId = unitTypeId;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    final UnitCriteria that = (UnitCriteria) o;
    return (Objects.equals(id, that.id) && Objects.equals(code, that.code) && Objects.equals(name, that.name)
        && Objects.equals(symbol, that.symbol) && Objects.equals(description, that.description)
        && Objects.equals(unitTypeId, that.unitTypeId) && super.equals(o));
  }

  @Override
  public int hashCode() {
    return Objects.hash(id, code, name, symbol, description, unitTypeId, super.hashCode());
  }

  // prettier-ignore
  @Override
  public String toString() {
    return "UnitCriteria{" + optionalId().map(f -> "id=" + f + ", ").orElse("")
        + optionalCode().map(f -> "code=" + f + ", ").orElse("")
        + optionalName().map(f -> "name=" + f + ", ").orElse("")
        + optionalSymbol().map(f -> "symbol=" + f + ", ").orElse("")
        + optionalDescription().map(f -> "description=" + f + ", ").orElse("")
        + optionalUnitTypeId().map(f -> "unitTypeId=" + f + ", ").orElse("") + super.toString() + "}";
  }
}
