package org.eco.generator.config;

import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

/**
 * 读取代码生成相关配置
 *
 * @author wgk
 */
@Component
@ConfigurationProperties(prefix = "gen")
@PropertySource(value = {"classpath:generator.yml"}, encoding = "UTF-8")
public class GenConfig {
    /**
     * 作者
     */
    @Getter
    public static String author;

    /**
     * 生成包路径
     */
    @Getter
    public static String packageName;

    /**
     * 自动去除表前缀，默认是false
     */
    public static boolean autoRemove;

    /**
     * 表前缀(类名不会包含表前缀)
     */
    @Getter
    public static String tablePrefix;

    /**
     * 表后缀(类名不会包含表后缀)
     */
    @Getter
    public static String tableSuffix;

    @Value("${author}")
    public void setAuthor(String author) {
        GenConfig.author = author;
    }

    @Value("${packageName}")
    public void setPackageName(String packageName) {
        GenConfig.packageName = packageName;
    }

    public static boolean getAutoRemove() {
        return autoRemove;
    }

    @Value("${autoRemove}")
    public void setAutoRemove(boolean autoRemove) {
        GenConfig.autoRemove = autoRemove;
    }

    @Value("${tablePrefix}")
    public void setTablePrefix(String tablePrefix) {
        GenConfig.tablePrefix = tablePrefix;
    }

    @Value("${tableSuffix}")
    public void setTableSuffix(String tableSuffix) {
        GenConfig.tableSuffix = tableSuffix;
    }
}
