package com.dev.swms.server.model.base;

import java.util.HashSet;
import java.util.Set;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

import com.dev.energy.server.model.Entity;

public class Warehouse extends Entity {
	/** 代码 */
	private String code;
	/** 名称 */
	private String name;
	/** 简称 */
	private String shortName;
	/** 地址 */
	private Address address;
	/** 联系方式 */
	private Contact contact;
	/** 描述 */
	private String description;
	/** 业务模型 */
	private String referenceModel;
	/** 包含库位 */
	private Set<Location> locations;
	/** 用户仓库 */
	private Set<UserGroupWarehouse> userGroupWarehouses;
	/** 是否有效 */
	private boolean disabled = false;
	/** x坐标 */
	private int x_Pos;
	/** y坐标 */
	private int y_Pos;
	/** 库区背景图 */
	private String image_url;

	public String getImage_url() {
		return image_url;
	}

	public void setImage_url(String image_url) {
		this.image_url = image_url;
	}

	public int getX_Pos() {
		return x_Pos;
	}

	public void setX_Pos(int pos) {
		x_Pos = pos;
	}

	public int getY_Pos() {
		return y_Pos;
	}

	public void setY_Pos(int pos) {
		y_Pos = pos;
	}

	public boolean isDisabled() {
		return disabled;
	}

	public void setDisabled(boolean disabled) {
		this.disabled = disabled;
	}

	protected Warehouse() {

	}

	public Set<Location> getLocations() {
		return locations;
	}

	public void setLocations(Set<Location> locations) {
		this.locations = locations;
	}

	public String getReferenceModel() {
		return referenceModel;
	}

	public void setReferenceModel(String referenceModel) {
		this.referenceModel = referenceModel;
	}

	public Set<UserGroupWarehouse> getUserGroupWarehouses() {
		return userGroupWarehouses;
	}

	public void setUserGroupWarehouses(Set<UserGroupWarehouse> userGroupWarehouses) {
		this.userGroupWarehouses = userGroupWarehouses;
	}

	// 返回已经被授予当前仓库的用户组
	public Set getInvokeUsers() {
		Set users = new HashSet();
		for (UserGroupWarehouse userGroupWarehouse : userGroupWarehouses) {
			users.add(userGroupWarehouse.getUserGroup());
		}
		return users;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Address getAddress() {
		return address;
	}

	public void setAddress(Address address) {
		this.address = address;
	}

	public Contact getContact() {
		return contact;
	}

	public void setContact(Contact contact) {
		this.contact = contact;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public boolean equals(final Object other) {
		if (!(other instanceof Structure))
			return false;
		Structure castOther = (Structure) other;
		return new EqualsBuilder().append(code, castOther.getCode()).isEquals();
	}

	public int hashCode() {
		return new HashCodeBuilder().append(code).toHashCode();
	}

	public String getShortName() {
		return shortName;
	}

	public void setShortName(String shortName) {
		this.shortName = shortName;
	}
}
