package com.oguerreiro.resilient.service.criteria;

import java.io.Serializable;
import java.util.Objects;
import java.util.Optional;

import com.oguerreiro.resilient.domain.enumeration.DataSourceType;

import tech.jhipster.service.Criteria;
import tech.jhipster.service.filter.Filter;

public abstract class AbstractCriteria implements Serializable, Criteria {
  private static final long serialVersionUID = 1L;

  /**
   * Class for filtering DataSourceType
   */
  public static class DataSourceTypeFilter extends Filter<DataSourceType> {

    private static final long serialVersionUID = 1L;

    public DataSourceTypeFilter() {
    }

    public DataSourceTypeFilter(DataSourceTypeFilter filter) {
      super(filter);
    }

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

  private Boolean distinct;

  public AbstractCriteria() {
  }

  public AbstractCriteria(AbstractCriteria other) {
    this.distinct = other.distinct;
  }

  public Boolean getDistinct() {
    return distinct;
  }

  public Optional<Boolean> optionalDistinct() {
    return Optional.ofNullable(distinct);
  }

  public Boolean distinct() {
    if (distinct == null) {
      setDistinct(true);
    }
    return distinct;
  }

  public void setDistinct(Boolean distinct) {
    this.distinct = distinct;
  }

  @Override
  public boolean equals(Object o) {
    final AbstractCriteria that = (AbstractCriteria) o;
    return Objects.equals(distinct, that.distinct);
  }

  @Override
  public int hashCode() {
    return Objects.hash(distinct);
  }

  @Override
  public String toString() {
    return optionalDistinct().map(f -> "distinct=" + f + ", ").orElse("");
  }
}
