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.PurchaseChange;
import com.uas.platform.b2b.mobile.service.PurchaseChangeService;
import com.uas.platform.b2b.model.PurchaseOrderChange;
import com.uas.platform.core.model.PageInfo;

@Service("mobile.PurchaseChangeService")
public class PurchaseChangeServiceImpl implements PurchaseChangeService {

	@Override
	public Page<PurchaseChange> convertPurchaseOrderChange(final Page<PurchaseOrderChange> orderChangePage) {
		List<PurchaseChange> changes = new ArrayList<PurchaseChange>();
		List<PurchaseOrderChange> orders = orderChangePage.getContent();
		if (!CollectionUtils.isEmpty(orders)) {
			for (PurchaseOrderChange order : orders) {
				changes.add(new PurchaseChange(order));
			}
		}
		return new PageImpl<PurchaseChange>(changes, new PageInfo(orderChangePage.getNumber(), orderChangePage.getSize()),
				orderChangePage.getTotalElements());
	}

	@Override
	public PurchaseChange convertPurchaseOrderChange(PurchaseOrderChange orderChange) {
		return new PurchaseChange(orderChange);
	}

}
