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

import java.util.Set;

import com.dev.energy.server.model.Entity;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

public class Stowage extends Entity {
	/**
	 * 所属仓库
	 */
	private Warehouse warehouse;
	/**
	 * 编码
	 */
	private String code;
	/**
	 * 名称
	 */
	private String name;
	/**
	 * 包含库位
	 */
	private Set<Location> locations;
	/**
	 * 长(米)
	 */
	private double length;
	/**
	 * 宽(米)
	 */
	private double width;
	/**
	 * 高(米)
	 */
	private double height;
	/**
	 * 体积(立方米)
	 */
	private double volume;
	/**
	 * 重量(公斤)
	 */
	private double weight;
	/**
	 * 数量(MU)
	 */
	private double quantity;
	
	/**
	 * 托盘数量限制
	 */
	private int lpLimit;
	
	/**
	 * 库满度百分比(90%-95%)，不让库位被放满，便于拣货
	 */
	private double fullRate;
	/**
	 * 描述
	 */
	private String description;
	/** 
	 * 是否有效 
	 */
	private boolean disabled = false;
	
	
	public int getLpLimit() {
		return lpLimit;
	}
	public void setLpLimit(int lpLimit) {
		this.lpLimit = lpLimit;
	}
	public Warehouse getWarehouse() {
		return warehouse;
	}
	public void setWarehouse(Warehouse warehouse) {
		this.warehouse = warehouse;
	}
	public boolean isDisabled() {
		return disabled;
	}
	public void setDisabled(boolean disabled) {
		this.disabled = disabled;
	}
	protected Stowage() {
		super();
	}
	public double getFullRate() {
		return fullRate;
	}
	public void setFullRate(double fullRate) {
		this.fullRate = fullRate;
	}
	public double getHeight() {
		return height;
	}
	public void setHeight(double height) {
		this.height = height;
	}
	public double getLength() {
		return length;
	}
	public void setLength(double length) {
		this.length = length;
	}
	public double getVolume() {
		return volume;
	}
	public void setVolume(double volume) {
		this.volume = volume;
	}
	public double getWeight() {
		return weight;
	}
	public void setWeight(double weight) {
		this.weight = weight;
	}
	public double getWidth() {
		return width;
	}
	public void setWidth(double width) {
		this.width = width;
	}
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public Set<Location> getLocations() {
		return locations;
	}
	public void setLocations(Set<Location> locations) {
		this.locations = locations;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public double getQuantity() {
		return quantity;
	}
	public void setQuantity(double quantity) {
		this.quantity = quantity;
	}

	public boolean inUse() {
		if ((this.locations == null || this.locations.size() == 0)) {
			return false;
		}
		for (Location location : this.locations) {
			if (!location.isDisabled()) {
				return true;
			}
		}
		return false;
	}
	
	public boolean equals(final Object other) {
		if (!(other instanceof Stowage))
			return false;
		Stowage castOther = (Stowage) other;
		return new EqualsBuilder().append(warehouse, castOther.getWarehouse())
				.append(code, castOther.getCode()).isEquals();
	}
	public int hashCode() {
		return new HashCodeBuilder().append(warehouse).append(code)
				.toHashCode();
	}
	
	public boolean match(PackageUnit packageUnit) {
		if (packageUnit.getLength() > this.length 
				|| packageUnit.getWidth() > this.width
				|| packageUnit.getHeight() > this.height) {
			return false;
		}
		return true;
	}

}
