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

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import com.uas.platform.b2b.history.dao.PurchaseInquiryDao;
import com.uas.platform.b2b.history.dao.PurchaseInquiryItemDao;
import com.uas.platform.b2b.history.model.PurchaseInquiry;
import com.uas.platform.b2b.history.model.PurchaseInquiryItem;
import com.uas.platform.b2b.history.service.PurchaseInquiryService;
import com.uas.platform.core.model.PageInfo;

@Service("history.PurchaseInquiryService")
public class PurchaseInquiryServiceImpl implements PurchaseInquiryService {

	@Autowired
	private PurchaseInquiryItemDao purchaseInquiryItemDao;

	@Autowired
	private PurchaseInquiryDao purchaseInquiryDao;

	@Override
	public Page<PurchaseInquiryItem> findAllByPageInfo(final PageInfo pageInfo) {
		return purchaseInquiryItemDao.findAll(new Specification<PurchaseInquiryItem>() {

			public Predicate toPredicate(Root<PurchaseInquiryItem> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
				query.where(pageInfo.getPredicates(root, query, builder));
				return null;
			}
		}, pageInfo);
	}

	@Override
	public PurchaseInquiry findById(Long id) {
		return purchaseInquiryDao.findOne(id);
	}

	@Override
	public PurchaseInquiryItem findItemByItemId(Long itemId) {
		return purchaseInquiryItemDao.findOne(itemId);
	}

}
