package com.njzscloud.common.gen.support;

import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import org.beetl.core.Context;
import org.beetl.core.Function;

import java.util.Map;

public final class Btl {
    public static final Function toCamelCase = (Object[] paras, Context ctx) -> StrUtil.toCamelCase(paras[0].toString());
    public static final Function upperFirst = (Object[] paras, Context ctx) -> StrUtil.upperFirst(paras[0].toString());
    public static final Function isBlank = (Object[] paras, Context ctx) -> StrUtil.isBlank(paras[0].toString());
    public static final Function subAfter = (Object[] paras, Context ctx) -> StrUtil.subAfter(paras[0].toString(), paras[1].toString(), false);
    public static final Function sqlDataTypeMap = new Function() {
        private final Map<String, Map<String, String>> map = MapUtil.<String, Map<String, String>>builder()
                .put("DEFAULT", MapUtil.<String, String>builder().put("importStatement", "").put("dataType", "").build())
                .put("VARCHAR", MapUtil.<String, String>builder().put("importStatement", "").put("dataType", "String").build())
                .put("CHAR", MapUtil.<String, String>builder().put("importStatement", "").put("dataType", "String").build())
                .put("LONGTEXT", MapUtil.<String, String>builder().put("importStatement", "").put("dataType", "String").build())
                .put("TEXT", MapUtil.<String, String>builder().put("importStatement", "").put("dataType", "String").build())
                .put("BIT", MapUtil.<String, String>builder().put("importStatement", "").put("dataType", "Boolean").build())
                .put("TINYINT", MapUtil.<String, String>builder().put("importStatement", "").put("dataType", "Integer").build())
                .put("SMALLINT", MapUtil.<String, String>builder().put("importStatement", "").put("dataType", "Integer").build())
                .put("MEDIUMINT", MapUtil.<String, String>builder().put("importStatement", "").put("dataType", "Integer").build())
                .put("INT", MapUtil.<String, String>builder().put("importStatement", "").put("dataType", "Integer").build())
                .put("BIGINT", MapUtil.<String, String>builder().put("importStatement", "").put("dataType", "Long").build())
                .put("DOUBLE", MapUtil.<String, String>builder().put("importStatement", "").put("dataType", "DOUBLE").build())
                .put("DECIMAL", MapUtil.<String, String>builder().put("importStatement", "import java.math.BigDecimal;").put("dataType", "BigDecimal").build())
                .put("DATE", MapUtil.<String, String>builder().put("importStatement", "import java.time.LocalDate;").put("dataType", "LocalDate").build())
                .put("TIME", MapUtil.<String, String>builder().put("importStatement", "import java.time.LocalTime;").put("dataType", "LocalTime").build())
                .put("DATETIME", MapUtil.<String, String>builder().put("importStatement", "import java.time.LocalDateTime;").put("dataType", "LocalDateTime").build())
                .build();

        @Override
        public Object call(Object[] paras, Context ctx) {
            return map.getOrDefault(paras[0].toString().toUpperCase(), map.get("DEFAULT"));
        }
    };
}
