package com.persagy.adm.server.custom.util;

import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;

/**
 * 实体对象id生成器
 */
public class IdGenerator {

	public static final String PROJECT = "project"; //项目
	public static final String BUILDING = "building"; //建筑
	public static final String FLOOR = "floor"; //"楼层"),
	public static final String SPACE = "space"; //空间
	public static final String SYSTEM = "system"; //系统
	public static final String EQUIPMENT = "equipment"; //设备
	public static final String SHAFT = "shaft"; //竖井
	public static final String COMPONENT = "component"; //部件
	public static final String VIRTUAL = "virtual"; //虚拟对象
	public static final String TOOL = "tool"; //工具
	public static final String MATERIAL = "material"; //耗材

	/**
	 * 生成对象id
	 * @param projectId 项目id
	 * @param objType 对象类型
	 * @return 两位prefix + 无前缀projectId + 无分隔符的32位uuid
	 */
	public static String getId(String projectId, String objType){
		if (PROJECT.equals(objType))
			return projectId;

		String prefix = getPrefix(objType);
		if(StrUtil.isBlank(prefix))
			return IdUtil.simpleUUID();

		return prefix + projectId.substring(2) + IdUtil.simpleUUID();
	}

	private static String getPrefix(String objType){
		switch (objType) {
			case PROJECT:
				return "Pj";
			case BUILDING:
				return "Bd";
			case FLOOR:
				return "Fl";
			case SPACE:
				return "Sp";
			case SYSTEM:
				return "Sy";
			case EQUIPMENT:
				return "Eq";
			case SHAFT:
				return "Sh";
			case COMPONENT:
				return "Ec";
			case VIRTUAL:
				return "Vo";
			case TOOL:
				return "To";
			case MATERIAL:
				return "Ma";
		}
		return null;
	}

}
