package com.wx.application.nebula.graph.base;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.wx.application.nebula.graph.bean.NebulaField;

public class FieldsUtils {
	

	/**
	 * 字段处理属性逻辑
	 * @param fields
	 * @return
	 */
	public static String toStringFields(List<NebulaField> fields) {
		if(fields == null || fields.size() == 0) {
			return "";
		}
		List<String> list = new ArrayList<>();
		if(fields != null) {
			for(NebulaField fn : fields) {
				list.add(toStringField(fn));
			}
		}
		return StringUtils.join(list.toArray(), ",");
	}
	
	
	
	public static String toStringField(NebulaField field) {
		String ft = field.getField() + " " + field.getType().name();
		if(StringUtils.isNotBlank(field.getComment())) {
			ft = ft + " COMMENT " + "\""+ field.getComment() +"\"";
		}
		return ft;
	}
	
	
	public static String toStringFieldNames(List<NebulaField> fields) {
		if(fields == null) {
			return "";
		}
		List<String> list = new ArrayList<>();
		for(NebulaField fn : fields) {
			list.add(fn.getField());
		}
		return StringUtils.join(list.toArray(), ",");
	}
	
	
	public static String toIndexFields(List<NebulaField> fields) {
		if(fields == null) {
			return "";
		}
		List<String> list = new ArrayList<>();
		for(NebulaField fn : fields) {
			list.add(toStringFieldIndex(fn.getField(),fn.getLen()));
		}
		return StringUtils.join(list.toArray(), ",");
	}
	
	
	public static String toStringFieldIndex(String fieldName,Integer len) {
		if(len != null && len > 0) {
			return fieldName + "(" + len + ")";
		}
		return fieldName;
	}
	
}
