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


import com.google.common.collect.Lists;
import com.purui.prims.common.pojo.QueryAuthorization;
import com.purui.prims.common.pojo.QueryColumn;
import com.purui.prims.headless.api.pojo.QueryResult;
import com.purui.prims.headless.api.pojo.enums.SemanticType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Data
@ToString
@Api(tags = "语义查询结果")
public class SemanticQueryResp extends QueryResult<Map<String, Object>> {

    @ApiModelProperty(value = "查询结果列")
    List<QueryColumn> columns = Lists.newArrayList();

    @ApiModelProperty(value = "查询语句")
    String sql;

    @ApiModelProperty(value = "查询权限")
    QueryAuthorization queryAuthorization;

    @ApiModelProperty(value = "是否使用缓存")
    boolean useCache;

    public List<QueryColumn> getMetricColumns() {
        return columns.stream()
                .filter(queryColumn -> SemanticType.NUMBER.name().equals(queryColumn.getShowType()))
                .collect(Collectors.toList());
    }

    public List<QueryColumn> getDimensionColumns() {
        return columns.stream()
                .filter(queryColumn -> !SemanticType.NUMBER.name().equals(queryColumn.getShowType()))
                .collect(Collectors.toList());
    }
}
