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

import cn.hutool.core.lang.Tuple;
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 AcctItemTableAdder extends AbstractAdder {
    private final ImmutableList<Tuple> mappings = Lists.immutable.of(
            new Tuple("fs", "757", "fs"),
            new Tuple("dg", "769", "dg"),
            new Tuple("dg", "668", "mm"),
            new Tuple("dg", "756", "zh"),
            new Tuple("dg", "759", "zj"),
            new Tuple("dg", "760", "zs"),
            new Tuple("dg", "763", "qy"),
            new Tuple("gz", "200", "gz"),
            new Tuple("gz", "662", "yj"),
            new Tuple("gz", "750", "jm"),
            new Tuple("gz", "752", "hz"),
            new Tuple("gz", "754", "st"),
            new Tuple("gz", "766", "yf"),
            new Tuple("gz", "768", "cz"),
            new Tuple("sz", "755", "sz"),
            new Tuple("sz", "660", "sw"),
            new Tuple("sz", "663", "jy"),
            new Tuple("sz", "751", "sg"),
            new Tuple("sz", "753", "mz"),
            new Tuple("sz", "758", "zq"),
            new Tuple("sz", "762", "hy"),
            new Tuple("szx", "93", "qs")
    );

    public AcctItemTableAdder(InfoService infoService, String database, String type, String schema, String table, String pulsarAddress, String hdfs) {
        super(infoService, database, type, schema, table, pulsarAddress, hdfs);
    }

    @Override
    protected ImmutableList<Job> getJobs() {
        return Lists.immutable.of(
                new Job(
                        snowflake.nextId(),
                        "acct acct_item",
                        FlinkJob.RunMode.ONE_IN_ONE.name(),
                        mappings.collect(tuple -> {
                            String area = tuple.get(0);
                            String code = tuple.get(1);
                            String city = tuple.get(2);
                            return new Table(
                                    snowflake.nextId(),
                                    StrUtil.format("{}_{}_{}", schema, table, city),
                                    3L,
                                    3L,
                                    4L,
                                    StrUtil.format("{}_{}", database, area),
                                    type,
                                    StrUtil.format("{}_{}", schema, area),
                                    table,
                                    pulsarAddress,
                                    StrUtil.format("persistent://odcp/{}_{}/{}_{}", schema, area, table, code),
                                    StrUtil.format("dws_{}", schema),
                                    StrUtil.format("dws_{}_{}", table, city),
                                    StrUtil.format("{}/dws_{}/external_table_hudi/dws_{}_{}", hdfs, schema, table, city),
                                    null,
                                    null,
                                    "NONE",
                                    50L
                            );
                        }),
                        true
                )
        );
    }
}
