package lc.mecha.sort;

import java.util.Objects;

/**
 * Indicates that a field with the given key should be sorted in either an ascending or descending fashion.
 *
 * @author Alex Leigh
 */
public class FieldSort {
    private final String key;
    private final SortCardinality cardinality;

    public FieldSort(String key, SortCardinality cardinality) {
        this.key = key;
        this.cardinality = cardinality;
    }

    public String getKey() {
        return key;
    }

    public SortCardinality getCardinality() {
        return cardinality;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        FieldSort that = (FieldSort) o;
        return Objects.equals(key, that.key) &&
                cardinality == that.cardinality;
    }

    @Override
    public int hashCode() {
        return Objects.hash(key, cardinality);
    }

    @Override
    public String toString() {
        return "SortPolicy{" +
                "key='" + key + '\'' +
                ", cardinality=" + cardinality +
                '}';
    }
}
