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

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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import com.uas.platform.b2b.dao.ProductDao;
import com.uas.platform.b2b.erp.model.Prod;
import com.uas.platform.b2b.erp.service.ProdService;
import com.uas.platform.b2b.model.Product;
import com.uas.platform.b2b.support.SystemSession;

@Service
public class ProdServiceImpl implements ProdService {
	
	@Autowired
	private ProductDao productDao;

	@Override
	public List<Product> convertProduct(List<Prod> prods) {
		List<Product> products = new ArrayList<Product>();
		long enUU = SystemSession.getUser().getEnterprise().getUu();
		for(Prod prod:prods) {
			List<Product> prodResult = productDao.findByEnUUAndCode(enUU, prod.getPr_code());
			if(CollectionUtils.isEmpty(prodResult))
				products.add(prod.convert());
		}
		return products;
	}
	
}
