package cn.com.origin.autocode.newitem.generatcode;

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

import com.teamcenter.rac.kernel.ListOfValuesInfo;
import com.teamcenter.rac.kernel.TCComponentListOfValues;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCProperty;
import com.teamcenter.rac.kernel.TCPropertyDescriptor;
import com.teamcenter.soa.client.model.LovValue;

public class CNObjectPropBean {
	public static final int PROP_ITEM = 0;				//属性来源于item
	public static final int PROP_ITEM_MASTER = 1;		//属性来源于item表单
	public static final int PROP_ITEM_REV = 2;			//属性来源于版本
	public static final int PROP_ITEM_REV_MASTER = 3;	//属性来源于版本表单
	
	public int propFrom ;
	public String displayName;					//属性显示名称
	public String realName;						//属性真实名称
	public String disValue;						//属性显示值
	public String realValue;					//属性真实值
	public Boolean isLov;						//是否关联LOV
	public Integer propType;					//属性类型
	public HashMap<String, String> lovKeyValue; //lov属性键值对
	public TCProperty tcProp;      				//TC对应的属性
	public List<String> keyList;				//lov显示值列表
	
	
	/**
	 * 构造方法
	 * @param tcProp  属性对象
	 * @param propFrom 属性来源
	 */
	public CNObjectPropBean(TCProperty tcProp,int propFrom){
		if(tcProp!=null){
			return;
		}
		this.propFrom = propFrom;
		this.tcProp = tcProp;
		setPropInfo(tcProp);
	}
	
	/**
	 * 获取TC属性信息
	 * @param tcProp
	 */
	private void setPropInfo(TCProperty tcProp){
		
		TCPropertyDescriptor propDesc =tcProp.getDescriptor();
		TCComponentListOfValues lov = tcProp.getLOV();
		
		this.displayName = propDesc.getDisplayName();
		this.realName = propDesc.getName();
		this.lovKeyValue = new HashMap<>();
		this.keyList = new ArrayList<>();
		this.propType = tcProp.getPropertyType();
		if(lov == null){
			this.isLov = false;
		}else{
			this.isLov = true;
			try {
				ListOfValuesInfo lovInfo = lov.getListOfValues();
				List<LovValue> lovValueList = lovInfo.getValues();
				for (LovValue lovV : lovValueList) {
					//lovDisValueStrList.add(lovV.getDisplayValue());
					lovKeyValue.put( lovV.getDisplayValue(),lovV.getStringValue());
					//lovValueStrList.add(lovV.getStringValue());
					keyList.add(lovV.getDisplayValue());
				}
			} catch (TCException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	/**
	 * 显示属性的显示名称
	 */
	@Override
	public String toString() {
		return displayName + ":";
	}
	
}
