package com.bocloud.ims.entity.topology;

import com.bocloud.entity.annotations.Column;
import com.bocloud.entity.annotations.IgnoreAll;
import com.bocloud.entity.annotations.PK;
import com.bocloud.entity.annotations.Table;
import com.bocloud.entity.bean.Generic;
import com.bocloud.entity.meta.PKStrategy;
import com.bocloud.ims.entity.enums.PropertyType;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * property实体类
 * 
 * @author lyy
 * @Version 1.0
 * @since 2017年9月13日
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Table("ci_property")
public class Property extends Generic {
	@PK(value = PKStrategy.AUTO)
	private Long id;
	@Column("code")
	private String code;
	@Column("name")
	private String name;
	/**
	 * 0:单行文本 1:多行文本 2:下拉菜单 3:单选 4:多选 5:引用 6:日期 7:加密 8:整数 9:小数10:表格
	 */
	@Column("type")
	private String type;
	@Column("group_name")
	private String groupName;
	@Column("min_value")
	private Integer minValue;
	@Column("max_value")
	private Integer maxValue;
	@Column("length")
	private Integer length;
	@Column("is_required")
	private Boolean required;
	@Column("link_module_id")
	private Long linkModuleId;
	@Column("default_value")
	private String defaultValue;
	@Column("is_uniqued")
	private Boolean uniqued;
	@Column("order_num")
	private Integer orderNum;
	@Column("decimal_num")
	private Integer decimalNum;
	@Column("unit")
	private String unit;
	@Column("module_id")
	private Long moduleId;
	@Column("regexp_id")
	private Long regexpId;
	@Column("is_reserved")
	private Boolean reserved;
	@Column("is_auto_discovery")
	private Boolean autoDiscovery;
	@Column("is_title")
	private Boolean title;
	@IgnoreAll
	private Boolean checked;
	@IgnoreAll
	private String propertyValue;
	@IgnoreAll
	private String propertyName;
	@IgnoreAll
	private List<InstanceGrid> grid;
	@IgnoreAll
	private String expression;
	@IgnoreAll
	private String message;

	public Property(String code, String name, String type, String groupName, int length, Boolean required,
                    Boolean uniqued, int orderNum, Long moduleId, Boolean reserved, Boolean autoDiscovery, Boolean title) {
		super();
		this.code = code;
		this.name = name;
		this.type = type;
		this.groupName = groupName;
		this.length = length;
		this.required = required;
		this.uniqued = uniqued;
		this.orderNum = orderNum;
		this.moduleId = moduleId;
		this.reserved = reserved;
		this.autoDiscovery = autoDiscovery;
		this.title = title;
	}

	// 非表中字段
	@IgnoreAll
	private List<PropertyItem> item;

	public boolean isTextfield() {
		return PropertyType.TEXTFIELD.name().equals(type);

	}

	public boolean isTextarea() {
		return PropertyType.TEXTAREA.name().equals(type);

	}

	public boolean isSelect() {
		return PropertyType.SELECT.name().equals(type);

	}

	public boolean isCheckBox() {
		return PropertyType.CHECKBOX.name().equals(type);

	}

	public boolean isQuote() {
		return PropertyType.QUOTE.name().equals(type);

	}

	public boolean isDate() {
		return PropertyType.DATE.name().equals(type);

	}

	public boolean isInteger() {
		return PropertyType.INTEGER.name().equals(type);

	}

	public boolean isFloat() {
		return PropertyType.FLOAT.name().equals(type);

	}

	public boolean isTable() {
		return PropertyType.TABLE.name().equals(type);

	}

	public boolean isTextencrypt() {
		return PropertyType.TEXTENCRYPT.name().equals(type);

	}

	public boolean isRedio() {
		return PropertyType.RADIO.name().equals(type);

	}

	public boolean isTime() {
		return PropertyType.TIME.name().equals(type);

	}

	/**
	 * 是否可能具备 item
	 * 
	 * @return
	 */
	public boolean isHaveItem() {
		if (isCheckBox() || isSelect() || isRedio() || isTable()) {
			return true;
		} else {
			return false;
		}
	}
}
