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

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

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import com.uas.platform.b2b.mobile.model.InquiryItem;
import com.uas.platform.b2b.mobile.service.InquiryItemService;
import com.uas.platform.b2b.model.PurchaseInquiryItem;
import com.uas.platform.core.model.PageInfo;

@Service("mobile.InquiryItemService")
public class InquiryItemServiceImpl implements InquiryItemService {

	@Override
	public Page<InquiryItem> convertInquiryItem(final Page<PurchaseInquiryItem> inquiryItemPage) {
		List<InquiryItem> inquiryItems = new ArrayList<InquiryItem>();
		List<PurchaseInquiryItem> purchaseInquiryItems = inquiryItemPage.getContent();
		if (!CollectionUtils.isEmpty(purchaseInquiryItems)) {
			for (PurchaseInquiryItem purchaseInquiryItem : purchaseInquiryItems) {
				inquiryItems.add(new InquiryItem(purchaseInquiryItem));
			}
		}
		return new PageImpl<InquiryItem>(inquiryItems, new PageInfo(inquiryItemPage.getNumber(), inquiryItemPage.getSize()), inquiryItemPage.getTotalElements());
	}

	@Override
	public InquiryItem convertInquiryItem(PurchaseInquiryItem inquiryItem) {
		return new InquiryItem(inquiryItem);
	}

}
