package io.delphiplatform.api.v3.bigtable.config;

import org.apache.commons.lang3.tuple.Pair;

import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.ToString;

/**
 * Instance of this class should be created to query particular row(s) from BT.
 * <p>
 * It contains rowkey string (full or part of it) or rowkeys range pair, and additional attributes of particular query
 */
@Builder
@ToString
@EqualsAndHashCode
public class RequestRowKeyHandle {

    private RowKeyPrefix rowKeyPrefix;

    //search this handle's rowkey as exact match, as rowkeys range, etc. See enum comments
    private RowKeyRequestType rowKeyRequestType;

    //pair will contain either:
    // - 1 value in left part: just a rowkey string (full or just leading segment(s)) - usually for "non-ranged" rowkey prefix (e.g. "id_genre~123~rock" or "id_genre~123")
    // - 2 values: start/end of rowkeys range, for "ranged" rowkey prefix (e.g. ["id_date~123~2023-01-01", "id_date~123~2023-12-12"])
    private Pair<String, String> rowKey;

    public Pair<String, String> getRowKeyRange() {
        return rowKey;
    }

    public String getRowKeyLeadingSegments() {
        return rowKey.getLeft();
    }

    public String getRowKeyExact() {
        return rowKey.getLeft();
    }

    public RowKeyPrefix getRowKeyPrefix() {
        return rowKeyPrefix;
    }

    public RowKeyRequestType getRowKeyRequestType() {
        return rowKeyRequestType;
    }
}
