package cz.inqool.dl4dh.krameriusplus;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

/**
 * @author Norbert Bodnar
 */
@Getter
@Setter
//TODO: only for BC, delete later
public class SolrToken {

    @JsonProperty("t")
    private String token;

    @JsonProperty("s")
    private int startOffset;

    @JsonProperty("e")
    private int endOffset;

    @JsonProperty("i")
    private int positionIncrement = 1;

    @JsonProperty("p")
    private String payload;

    public SolrToken(String indexedValue, int startOffset, int endOffset, String payload) {
        this.token = indexedValue;
        this.startOffset = startOffset;
        this.endOffset = endOffset;
        this.payload = Base64.getEncoder().encodeToString(payload.getBytes(StandardCharsets.UTF_8));
    }
}
