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

import java.util.HashSet;
import java.util.List;
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 Position extends Entity {
	/** 所属仓库 */
	private Warehouse warehouse;
	/** 编码 */
	private String code;
	/** 名称 */
	private String name;	
	/** 是否有效 */
	private boolean disabled = false;
	/** 描述 **/
	private String discription;
	/** 定位明细 */
	private Set<PositionDetail> details;
	
	/**库位明细*/
	private Set<Location> location;
	
	
	public Set<Location> getLocation() {
		return location;
	}

	public void setLocation(Set<Location> location) {
		this.location = location;
	}

	public String getCode() {
		return code;
	}

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

	public Set<PositionDetail> getDetails() {
		return details;
	}

	public void setDetails(Set<PositionDetail> details) {
		this.details = details;
	}

	public String getName() {
		return name;
	}

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

	public Warehouse getWarehouse() {
		return warehouse;
	}

	public void setWarehouse(Warehouse warehouse) {
		this.warehouse = warehouse;
	}

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

	@Override
	public boolean equals(Object other) {
		if(other instanceof Position){
			return false;
		}
		Position castOther = (Position) other;
		return new EqualsBuilder().append(warehouse, castOther.getWarehouse())
		.append(code, castOther.getCode()).isEquals();
	}

	public boolean isDisabled() {
		return disabled;
	}

	public void setDisabled(boolean disabled) {
		this.disabled = disabled;
	}
	
	public void addDetail(PositionDetail positionDetail){
		positionDetail.setPosition(this);
		if(this.details==null){
			this.details = new HashSet<PositionDetail>();
		}
		this.details.add(positionDetail);
	}
	
	public void deleteDetails(List<PositionDetail> positionDetails){
		for(PositionDetail detail:positionDetails){
			this.details.remove(detail);
		}
	}

	public String getDiscription() {
		return discription;
	}

	public void setDiscription(String discription) {
		this.discription = discription;
	}
}
