package com.docus.server;

import cn.smallbun.screw.core.Configuration;
import cn.smallbun.screw.core.engine.EngineConfig;
import cn.smallbun.screw.core.engine.EngineFileType;
import cn.smallbun.screw.core.engine.EngineTemplateType;
import cn.smallbun.screw.core.execute.DocumentationExecute;
import cn.smallbun.screw.core.process.ProcessConfig;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;

import javax.sql.DataSource;
import java.util.ArrayList;

@SpringBootTest
class ScrewTests {

    @Autowired
    private ApplicationContext applicationContext;

    @Test
    void test() {

        HikariConfig hikariConfig = new HikariConfig();
        hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver");
        hikariConfig.setJdbcUrl("jdbc:mysql://db.docus.cn:3306/docus-collector-scheduling?autoReconnect=true&allowMultiQueries=true&useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai");
        hikariConfig.setUsername("docus");
        hikariConfig.setPassword("docus702");
        //设置可以获取tables remarks信息
        hikariConfig.addDataSourceProperty("useInformationSchema", "true");
        hikariConfig.setMinimumIdle(2);
        hikariConfig.setMaximumPoolSize(5);
        DataSource dataSource = new HikariDataSource(hikariConfig);

        //生成文件配置
        EngineConfig engineConfig = EngineConfig
            .builder()
            //文件生成路径
            .fileOutputDir("h:\\file")
            //打开目录
            .openOutputDir(false)
            //文件类型
            .fileType(EngineFileType.HTML)
            //生成模板实现
            .produceType(EngineTemplateType.freemarker)
            .build();
        //配置想要生成的表
        ProcessConfig processConfig = ProcessConfig
            .builder()
            //根据名称指定表生成
            .designatedTableName(new ArrayList<>())
            //根据表前缀生成
            .designatedTablePrefix(new ArrayList<>())
            //根据表后缀生成
            .designatedTableSuffix(new ArrayList<>())
            //忽略表名
            .ignoreTableName(new ArrayList<>())
            //忽略表前缀
            .ignoreTablePrefix(new ArrayList<>())
            //忽略表后缀
            .ignoreTableSuffix(new ArrayList<>())
            .build();
        //生成文档配置
        Configuration configuration = Configuration.builder()
            .version("1.0.0")
            .description("描述")
            .dataSource(dataSource)
            .engineConfig(engineConfig)
            .produceConfig(processConfig)
            .build();

        //生成
        new DocumentationExecute(configuration).execute();
    }
}
