package com.uas.platform.b2b.erp.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import com.uas.platform.b2b.erp.model.RemoteFile;
import com.uas.platform.b2b.erp.model.SaleSampleApproval;
import com.uas.platform.b2b.erp.model.SaleSampleDown;
import com.uas.platform.b2b.erp.model.SaleSampleSend;
import com.uas.platform.b2b.erp.service.SaleSampleDownService;
import com.uas.platform.b2b.model.Attach;
import com.uas.platform.b2b.model.PurchaseProofingApproval;
import com.uas.platform.b2b.model.PurchaseProofingItem;
import com.uas.platform.b2b.model.PurchaseProofingSend;

@Service
public class SaleSampleDownServiceImpl implements SaleSampleDownService {
	
	@Override
	public List<SaleSampleDown> convertPurchaseProofingItems(
			List<PurchaseProofingItem> proofingItems) {
		List<SaleSampleDown> saleSampleDowns = new ArrayList<SaleSampleDown>();
		if(!CollectionUtils.isEmpty(proofingItems)) {
			for(PurchaseProofingItem proofingItem : proofingItems) {
				SaleSampleDown sampleDown = new SaleSampleDown(proofingItem);
				if (!CollectionUtils.isEmpty(proofingItem.getProofing().getAttachs())) {
					List<RemoteFile> files = new ArrayList<RemoteFile>();
					for (Attach attach : proofingItem.getProofing().getAttachs()) {
						files.add(new RemoteFile(attach));
					}
					sampleDown.setFiles(files);
				}
				saleSampleDowns.add(sampleDown);
			}
		}
		return saleSampleDowns;
	}

	@Override
	public List<SaleSampleSend> convertSaleSampleSends(
			List<PurchaseProofingSend> proofingSends) {
		List<SaleSampleSend> saleSampleSends = new ArrayList<SaleSampleSend>();
		if(!CollectionUtils.isEmpty(proofingSends)) {
			for(PurchaseProofingSend proofingSend : proofingSends){
				SaleSampleSend sampleSend = new SaleSampleSend(proofingSend);
				if (!CollectionUtils.isEmpty(proofingSend.getAttachs())) {
					List<RemoteFile> files = new ArrayList<RemoteFile>();
					for (Attach attach : proofingSend.getAttachs()) {
						files.add(new RemoteFile(attach));
					}
					sampleSend.setFiles(files);
				}
				saleSampleSends.add(sampleSend);
			}
		}
		return saleSampleSends;
	}

	@Override
	public List<PurchaseProofingSend> convertProofingSends(
			List<SaleSampleSend> saleSampleSends) {
		List<PurchaseProofingSend> proofingSends = new ArrayList<PurchaseProofingSend>();
		if(!CollectionUtils.isEmpty(saleSampleSends)) {
			for(SaleSampleSend saleSampleSend : saleSampleSends){
				proofingSends.add(saleSampleSend.convert());
			}
		}
		return proofingSends;
	}

	@Override
	public List<SaleSampleApproval> covertSampleApprovals(
			List<PurchaseProofingApproval> proofingApprovals) {
		List<SaleSampleApproval> saleSampleApprovals = new ArrayList<SaleSampleApproval>();
		if(!CollectionUtils.isEmpty(proofingApprovals)) {
			for(PurchaseProofingApproval proofingApproval : proofingApprovals) {
				SaleSampleApproval approval = new SaleSampleApproval(proofingApproval);
				//附件
				if (!CollectionUtils.isEmpty(proofingApproval.getAttachs())) {
					List<RemoteFile> files = new ArrayList<RemoteFile>();
					for (Attach attach : proofingApproval.getAttachs()) {
						files.add(new RemoteFile(attach));
					}
					approval.setFiles(files);
				}
				//prd附件
				if (!CollectionUtils.isEmpty(proofingApproval.getPrdAttachs())) {
					List<RemoteFile> files = new ArrayList<RemoteFile>();
					for (Attach attach : proofingApproval.getPrdAttachs()) {
						files.add(new RemoteFile(attach));
					}
					approval.setPrdfiles(files);
				}
				//pad附件
				if (!CollectionUtils.isEmpty(proofingApproval.getPadAttachs())) {
					List<RemoteFile> files = new ArrayList<RemoteFile>();
					for (Attach attach : proofingApproval.getPadAttachs()) {
						files.add(new RemoteFile(attach));
					}
					approval.setPadfiles(files);
				}
				//ppd附件
				if (!CollectionUtils.isEmpty(proofingApproval.getPpdAttachs())) {
					List<RemoteFile> files = new ArrayList<RemoteFile>();
					for (Attach attach : proofingApproval.getPpdAttachs()) {
						files.add(new RemoteFile(attach));
					}
					approval.setPpdfiles(files);
				}
				saleSampleApprovals.add(approval);
			}
		}
		return saleSampleApprovals;
	}


}
