package com.lanyuanxiaoyao.service.command.commands.jobs;

import cn.hutool.core.util.StrUtil;
import com.lanyuanxiaoyao.service.common.entity.FlinkJob;
import com.lanyuanxiaoyao.service.forest.service.InfoService;
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.list.ImmutableList;

/**
 * @date 2022-06-29
 */
public class SmallTableAdder extends AbstractAdder implements TableGetter {
    public SmallTableAdder(InfoService infoService, String database, String type, String schema, String table, String pulsarAddress, String hdfs) {
        super(infoService, database, type, schema, table, pulsarAddress, hdfs);
    }

    @Override
    public ImmutableList<Table> getTables() {
        return Lists.immutable.of(
                new Table(
                        snowflake.nextId(),
                        StrUtil.format("{}_{}", schema, table),
                        1L,
                        1L,
                        4L,
                        database,
                        type,
                        schema,
                        table,
                        pulsarAddress,
                        StrUtil.format("persistent://odcp/{}/{}", schema, table),
                        StrUtil.format("dws_{}", schema),
                        StrUtil.format("dws_{}", table),
                        StrUtil.format("{}/dws_{}/external_table_hudi/dws_{}", hdfs, schema, table),
                        null,
                        null,
                        "NONE",
                        1L
                )
        );
    }

    @Override
    protected ImmutableList<Job> getJobs() {
        return Lists.immutable.of(
                new Job(
                        snowflake.nextId(),
                        schema,
                        FlinkJob.RunMode.ALL_IN_ONE.name(),
                        getTables(),
                        true
                )
        );
    }
}
