package com.iamberry.wechat.service.cart;

import java.util.List;

import com.iamberry.wechat.core.entity.PageBean;
import com.iamberry.wechat.core.entity.product.ProductColor;
import com.iamberry.wechat.core.entity.product.QrcodeGift;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.iamberry.wechat.core.entity.cart.ShopOrderItemDto;
import com.iamberry.wechat.core.entity.cart.UserGiftDto;
import com.iamberry.wechat.core.entity.product.Product;
import com.iamberry.wechat.face.cart.ProductInfoService;
import com.iamberry.wechat.service.cart.dao.CartDao;
import com.iamberry.wechat.service.cart.dao.ProductInfoDao;

@Service
public class ProductInfoServiceImpl implements ProductInfoService {
	
	@Autowired
	private ProductInfoDao productInfoDao;
	
	@Autowired
	private CartDao cartDao;

	
	public List<Product> selectPageProduct(Product product) {
		// TODO Auto-generated method stub
		return productInfoDao.selectPageProduct(product);
	}
	
	@Override
	public List<Product> listSelectProduct(Product product) {
		// TODO Auto-generated method stub
		return productInfoDao.listSelectProduct(product);
	}



	public Product getProductByProductId(Integer productId, Integer colorId) {
		// TODO Auto-generated method stub
		return productInfoDao.getProductByProductId(productId,colorId);
	}

	
	public List<Product> getProductByProductName(String productName) {
		// TODO Auto-generated method stub
		return productInfoDao.getProductByProductName(productName);
	}

	public void cacheIndexPageProduct() {
		productInfoDao.selectIndexPageProduct();
	}
	
	public List<Product> selectIndexPageProduct() {
		// TODO Auto-generated method stub
		return productInfoDao.selectIndexPageProduct();
	}

	
	public Integer selectProductCount(Product product) {
		// TODO Auto-generated method stub
		return this.productInfoDao.selectProductCount(product);
	}

	
	public Integer updateProductNumList(String orderId) {
		// TODO Auto-generated method stub
		if (null == orderId || "".equals(orderId)) {
			return 0;
		}
		List<ShopOrderItemDto> orderItemList =  cartDao.selectShopOrderItem(orderId);
		if (orderItemList == null || orderItemList.size() <= 0) {
			return 0;
		}
		return productInfoDao.updateProductNumList(orderItemList);
	}


	@Override
	public UserGiftDto selectUserGift(UserGiftDto userGiftDto) {
		// TODO Auto-generated method stub
		return productInfoDao.selectUserGift(userGiftDto);
	}


	@Override
	public Product getLeaseProduct(Integer productId) {
		// TODO Auto-generated method stub
		return productInfoDao.getLeaseProduct(productId);
	}

    @Override
    public List<QrcodeGift> listQrcodeGift(QrcodeGift qrcodeGift) {
        return productInfoDao.listQrcodeGift(qrcodeGift);
    }

    @Override
    public Integer listQrcodeGiftCount(QrcodeGift qrcodeGift) {
        int count = productInfoDao.listQrcodeGiftCount(qrcodeGift);
        return	count = count % qrcodeGift.getPage().getPageSize() == 0? count/qrcodeGift.getPage().getPageSize():(count/qrcodeGift.getPage().getPageSize())+1;
    }

    @Override
    public Integer addQrcodeGift(QrcodeGift qrcodeGift) {
        return productInfoDao.addQrcodeGift(qrcodeGift);
    }

    @Override
    public Integer updateQrcodeGift(QrcodeGift qrcodeGift) {
        return productInfoDao.updateQrcodeGift(qrcodeGift);
    }

    @Override
    public Integer getQrCodeByPlaceOpenId(String openId) {
        return productInfoDao.getQrCodeByPlaceOpenId(openId);
    }

    @Override
    public Integer updateGiftStatus(QrcodeGift qrcodeGift) {
        return productInfoDao.updateGiftStatus(qrcodeGift);
    }

	@Override
	public ProductColor getProductColor(ProductColor productColor){
		return productInfoDao.getProductColor(productColor);
	}
}
