package com.purui.prims.headless.api.pojo.request;

import com.google.common.collect.Lists;
import com.purui.prims.headless.api.pojo.Cache;
import com.purui.prims.headless.api.pojo.Param;
import com.purui.prims.headless.api.pojo.SqlInfo;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;


@Data
@Slf4j
public abstract class SemanticQueryReq {

    protected boolean needAuth = true;

    protected boolean innerLayerNative = false;

    protected Long dataSetId;

    protected String dataSetName;

    protected Set<Long> modelIds = new HashSet<>();

    protected List<Param> params = new ArrayList<>();

    protected Cache cacheInfo = new Cache();

    protected SqlInfo sqlInfo = new SqlInfo();

    protected Map<String, String> rollOverMap = new HashMap<>(2);

    public void addModelId(Long modelId) {
        modelIds.add(modelId);
    }

    public String generateCommandMd5() {
        return DigestUtils.md5Hex(this.toCustomizedString());
    }

    public abstract String toCustomizedString();

    public List<Long> getModelIds() {
        return Lists.newArrayList(modelIds);
    }

    public Set<Long> getModelIdSet() {
        return modelIds;
    }

    public boolean isNeedAuth() {
        return needAuth;
    }

    public void setNeedAuth(boolean needAuth) {
        this.needAuth = needAuth;
    }
}
