package com.dev.swms.server.service.task.pojo;

import java.util.Collection;
import java.util.List;

import com.dev.swms.server.model.abstractEntity.AbstractMoveDocDetail;
import com.dev.swms.server.service.picking.allocate.AutoAllocator;
import com.dev.swms.server.service.receiving.PutawayAllocator;
import com.dev.swms.server.service.task.AllocateManager;
import com.dev.energy.server.util.LocalizedMessage;

public class DefaultAllocateManager implements AllocateManager {
	protected final PutawayAllocator putawayAllocator;
	protected final AutoAllocator autoAllocator;

	public DefaultAllocateManager(PutawayAllocator putawayAllocator, AutoAllocator autoAllocator) {
		super();
		this.putawayAllocator = putawayAllocator;
		this.autoAllocator = autoAllocator;
	}

	public void putawayAllocate(List<Long> moveDocIds) {
		for (Long moveDocId : moveDocIds) {
			String errorMsg = putawayAllocator.allocate(moveDocId);
			LocalizedMessage.addLocalizedMessage(errorMsg);
		}
	}

	public void allocate(List<Long> pickTicketIds, List<Long> waveDocIds,
			List<Long> moveDocIds, Collection<AbstractMoveDocDetail> details) {
		String errorMsg = "";
		if (pickTicketIds != null) {
			//走整单分配
			for (Long pickTicketId : pickTicketIds) {
				//
				errorMsg = autoAllocator.allocate(pickTicketId, null, null, null);
			}
		} else if (waveDocIds != null) {
			for (Long waveDocId : waveDocIds) {
				errorMsg = autoAllocator.allocate(null, waveDocId, null, null);
			}
		} else if (moveDocIds != null) {
			for (Long moveDocId : moveDocIds) {
				errorMsg = autoAllocator.allocate(null, null, moveDocId, null);
			}
		} else if (details != null) {
			errorMsg = autoAllocator.allocate(null, null, null, details);
		}
		LocalizedMessage.addLocalizedMessage(errorMsg);
	}

	public void pickAllocate(List<Long> pickTicketIds) {
		allocate(pickTicketIds, null, null, null);
	}

	public void waveAllocate(List<Long> waveDocIds) {
		allocate(null, waveDocIds, null, null);
	}
	
	public void moveAllocate(List<Long> moveDocIds) {
		allocate(null, null, moveDocIds, null);
	}
}
