package com.lanyuanxiaoyao.service.forest.service;

import com.dtflys.forest.annotation.BaseRequest;
import com.dtflys.forest.annotation.Body;
import com.dtflys.forest.annotation.Get;
import com.dtflys.forest.annotation.Post;
import com.dtflys.forest.annotation.Query;
import com.lanyuanxiaoyao.service.configuration.entity.PageResponse;
import com.lanyuanxiaoyao.service.configuration.entity.hudi.HPath;
import com.lanyuanxiaoyao.service.configuration.entity.hudi.HudiCleanerPlan;
import com.lanyuanxiaoyao.service.configuration.entity.hudi.HudiCompactionPlan;
import com.lanyuanxiaoyao.service.configuration.entity.hudi.HudiInstant;
import com.lanyuanxiaoyao.service.configuration.entity.hudi.HudiRollbackPlan;
import java.io.InputStream;
import java.util.Map;
import org.eclipse.collections.api.list.ImmutableList;
import org.eclipse.collections.api.map.ImmutableMap;

/**
 * Hudi 操作
 *
 * @author lanyuanxiaoyao
 * @date 2023-05-01
 */
@BaseRequest(baseURL = "http://service-hudi-query")
public interface HudiService {
    @Get("/timeline/list")
    PageResponse<HudiInstant> timelineList(@Query Map<String, Object> queryMap);

    @Get("/timeline/list_hdfs")
    PageResponse<HudiInstant> timelineHdfsList(@Query Map<String, Object> queryMap);

    @Get("/timeline/all?active=true&archive=false")
    ImmutableList<HudiInstant> timelineAllActive(@Query("flink_job_id") Long flinkJobId, @Query("alias") String alias);

    @Get("/timeline/all_hdfs?active=true&archive=false")
    ImmutableList<HudiInstant> timelineHdfsAllActive(@Query("hdfs") String hdfs);

    @Get("/timeline/all?active=false&archive=true")
    ImmutableList<HudiInstant> timelineAllArchive(@Query("flink_job_id") Long flinkJobId, @Query("alias") String alias);

    @Get("/timeline/all_hdfs?active=false&archive=true")
    ImmutableList<HudiInstant> timelineHdfsAllArchive(@Query("hdfs") String hdfs);

    @Get("/timeline/all")
    ImmutableList<HudiInstant> timelineAll(@Query("flink_job_id") Long flinkJobId, @Query("alias") String alias, @Query("active") Boolean active, @Query("archive") Boolean archive);

    @Get("/timeline/all_hdfs")
    ImmutableList<HudiInstant> timelineHdfsAll(@Query("hdfs") String hdfs, @Query("active") Boolean active, @Query("archive") Boolean archive);

    @Get("/timeline/read_compaction_plan")
    HudiCompactionPlan readCompactionPlan(@Query("flink_job_id") Long flinkJobId, @Query("alias") String alias, @Query("instant") String instant);

    @Get("/timeline/read_compaction_plan_hdfs")
    HudiCompactionPlan readCompactionPlanHdfs(@Query("hdfs") String hdfs, @Query("instant") String instant);

    @Get("/timeline/read_rollback_plan")
    HudiRollbackPlan readRollbackPlan(@Query("flink_job_id") Long flinkJobId, @Query("alias") String alias, @Query("instant") String instant);

    @Get("/timeline/read_rollback_plan_hdfs")
    HudiRollbackPlan readRollbackPlanHdfs(@Query("hdfs") String hdfs, @Query("instant") String instant);

    @Get("/timeline/read_cleaner_plan")
    HudiCleanerPlan readCleanerPlan(@Query("flink_job_id") Long flinkJobId, @Query("alias") String alias, @Query("instant") String instant);

    @Get("/timeline/read_cleaner_plan_hdfs")
    HudiCleanerPlan readCleanerPlanHdfs(@Query("hdfs") String hdfs, @Query("instant") String instant);

    @Get("/timeline/list_pending_compaction")
    ImmutableList<HudiInstant> timelinePendingCompactionList(@Query("flink_job_id") Long flinkJobId, @Query("alias") String alias);

    @Get("/timeline/exists_compaction_plan")
    Boolean existsCompactionPlan(@Query("flink_job_id") Long flinkJobId, @Query("alias") String alias);

    @Get("/table/schema")
    ImmutableMap<String, Object> schema(@Query("flink_job_id") Long flinkJobId, @Query("alias") String alias);

    @Get("/table/schema_hdfs")
    ImmutableMap<String, Object> schema(@Query("hdfs") String hdfs);

    @Get("/hdfs/exists_hudi_table_by_flink_job_id_alias")
    Boolean existsHudiTable(@Query("flink_job_id") Long flinkJobId, @Query("alias") String alias);

    @Get("/hdfs/exists_hudi_table_by_hdfs")
    Boolean existsHudiTable(@Query("hdfs") String hdfs);

    @Get("/hdfs/exists_path")
    Boolean existsPath(@Query("hdfs") String hdfs);

    @Get("/hdfs/get")
    HPath get(@Query("root") String root);

    @Get("/hdfs/list")
    ImmutableList<HPath> list(@Query("root") String root);

    @Get("/hdfs/read")
    String read(@Query("root") String root);

    @Post(value = "/hdfs/write", contentType = "plain/text")
    String write(@Query("root") String root, @Body String text);

    @Post(value = "/hdfs/write", contentType = "plain/text")
    String write(@Query("root") String root, @Body String text, @Query("overwrite") Boolean overwrite);

    @Get("/hdfs/download")
    InputStream download(@Query("root") String root);

    @Get("/hdfs/size")
    Long size(@Query("root") String root);

    @Get("/hdfs/count")
    Long count(@Query("root") String root);

    @Get("/hdfs/file_count")
    Long fileCount(@Query("root") String root);

    @Get("/hdfs/directory_count")
    Long directoryCount(@Query("root") String root);
}
