package com.mortals.xhx.base.system.gentable.model;

import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.github.javafaker.Faker;
import com.mortals.framework.model.BaseEntityLong;
import com.mortals.framework.util.DateUtils;
import com.mortals.xhx.common.utils.StringUtils;
import lombok.Data;
import org.springframework.util.ObjectUtils;

import java.util.List;
import java.util.Locale;
import java.util.Map;

/**
 * Description:GentableColumn
 * date: 2021-9-28 10:10:15
 */
@Data
public class GentableColumnEntityExt extends BaseEntityLong {

    private List<Map<String, String>> dict;


    public static String subComment(String comment) {

        if (comment.indexOf("(") != -1) {
            return comment.substring(0, comment.indexOf("("));
        }

        if (comment.indexOf("（") != -1) {
            return comment.substring(0, comment.indexOf("（"));
        }

        return comment;
    }

    public static String randomStr(GentableColumnEntity column) {

        String returnStr = "";

        if(!ObjectUtils.isEmpty(column.getDefaultValue())){
            returnStr =column.getDefaultValue();
        }else{
            if ("String".equalsIgnoreCase(column.getJavaType())) {
                returnStr = RandomUtil.randomString(6);
            } else if ("Integer".equalsIgnoreCase(column.getJavaType()) || "Long".equalsIgnoreCase(column.getJavaType())) {
                returnStr = RandomUtil.randomInt(0, 1000) + "";
            } else if ("BigDecimal".equalsIgnoreCase(column.getJavaType())) {
                returnStr = RandomUtil.randomBigDecimal().setScale(2, 1).doubleValue() + "";
            } else if ("date".equalsIgnoreCase(column.getJavaType())) {
                returnStr = DateUtils.getCurrDate().getTime()+"";
            }
        }


        return returnStr;
    }


    public static String randomStr(String javaType) {

        String returnStr = "";
        if ("String".equalsIgnoreCase(javaType)) {
            returnStr = RandomUtil.randomString(6);
        } else if ("Integer".equalsIgnoreCase(javaType) || "Long".equalsIgnoreCase(javaType)) {
            returnStr = RandomUtil.randomInt(0, 10000) + "";
        } else if ("BigDecimal".equalsIgnoreCase(javaType)) {
            returnStr = RandomUtil.randomBigDecimal().setScale(2, 1).doubleValue() + "";
        } else if ("date".equalsIgnoreCase(javaType)) {
            returnStr = DateUtils.getCurrStrDate();
        }
        return returnStr;
    }

    public static String randomNumber() {

        Faker faker = new Faker(Locale.CHINESE);
        return faker.number().numberBetween(0, 10000) + "";
    }

    public static String subBetween(String comment) {

        comment = comment.replaceAll("（", "(");
        comment = comment.replaceAll("）", ")");
        String max = StrUtil.subBetween(comment, "(", ")");

        return max == null ? "9999" : max;
    }


    public String test() {
        return "aaa";
    }


    public static void main(String[] args) {
        GentableColumnEntity gentableColumnEntity = new GentableColumnEntity();
        gentableColumnEntity.setCreateUser("bbbbbb");
        System.out.println(JSON.toJSONString(gentableColumnEntity));
        // System.out.println(gentableColumnEntity.test());


        System.out.println(DateUtils.getCurrDatetime().getTime());

    }

}