package com.purui.prims.headless.server.service;

import com.github.pagehelper.PageInfo;
import com.purui.prims.auth.api.authentication.pojo.User;
import com.purui.prims.common.pojo.DataEvent;
import com.purui.prims.common.pojo.PersistenceConf;
import com.purui.prims.common.pojo.enums.EventType;
import com.purui.prims.dscheduler.model.TaskInstance;
import com.purui.prims.dscheduler.model.TaskLog;
import com.purui.prims.headless.api.pojo.DrillDownDimension;
import com.purui.prims.headless.api.pojo.MetricQueryDefaultConfig;
import com.purui.prims.headless.api.pojo.request.MetaBatchReq;
import com.purui.prims.headless.api.pojo.request.MetricReq;
import com.purui.prims.headless.api.pojo.request.PageMetricReq;
import com.purui.prims.headless.api.pojo.request.QueryMetricReq;
import com.purui.prims.headless.api.pojo.request.QueryStructReq;
import com.purui.prims.headless.api.pojo.response.MetricResp;
import com.purui.prims.headless.api.pojo.response.ModelResp;
import com.purui.prims.headless.server.persistence.dataobject.MetricDO;
import com.purui.prims.headless.server.pojo.MetaFilter;
import com.purui.prims.headless.server.pojo.MetricFilter;
import com.purui.prims.headless.server.pojo.MetricsFilter;

import java.util.List;

public interface MetricService {

    MetricResp createMetric(MetricReq metricReq, User user) throws Exception;

    void createMetricBatch(List<MetricReq> metricReqs, User user) throws Exception;

    MetricResp updateMetric(MetricReq metricReq, User user) throws Exception;

    void batchUpdateStatus(MetaBatchReq metaBatchReq, User user);

    void batchPublish(List<Long> metricIds, User user);

    void batchUnPublish(List<Long> metricIds, User user);

    void batchUpdateClassifications(MetaBatchReq metaBatchReq, User user);

    void batchUpdateSensitiveLevel(MetaBatchReq metaBatchReq, User user);

    void deleteMetric(Long id, User user) throws Exception;

    PageInfo<MetricResp> queryMetricMarket(PageMetricReq pageMetricReq, User user);

    PageInfo<MetricResp> queryMetric(PageMetricReq pageMetricReq, User user);

    List<MetricDO> queryMetric(MetricFilter metricFilter);

    List<MetricResp> getMetrics(MetaFilter metaFilter);

    List<MetricResp> getMetricsToCreateNewMetric(Long modelId);

    MetricResp getMetric(Long modelId, String bizName);

    MetricResp getMetric(Long id, User user);

    MetricResp getMetric(Long id);

    MetricResp getLastVersionMetric(Long id);

    List<DrillDownDimension> getDrillDownDimension(Long metricId);

    void saveMetricQueryDefaultConfig(MetricQueryDefaultConfig defaultConfig, User user);

    MetricQueryDefaultConfig getMetricQueryDefaultConfig(Long metricId, User user);

    void sendMetricEventBatch(List<Long> modelIds, EventType eventType);

    List<MetricResp> queryMetrics(MetricsFilter metricsFilter);

    void batchFillMetricDefaultAgg(List<MetricResp> metricResps, List<ModelResp> modelResps);

    QueryStructReq convert(QueryMetricReq queryMetricReq);

    QueryMetricReq newQueryMetricReq(Long id);

    DataEvent getDataEvent();

    String buildMetricSql(ModelResp modelResp, List<MetricResp> metricDOs, boolean simplify, PersistenceConf conf, boolean addTimestamp);

    TaskLog queryTaskLog(Long metricId, int instanceId);

    List<TaskInstance> queryTaskInstances(Long metricId, String startDate, String endDate);

    boolean runTask(Long metricId);

    String getMetricTableName(Long metricId);

    void buildDependencyDAG(List<MetricResp> metricRespList);

    void buildAggregator(List<MetricResp> metricResps, QueryStructReq queryStructReq);

    void buildCastor(QueryStructReq queryStructReq, List<MetricResp> metricResps);

    String buildAsSelectSql(Long metricId);
}
