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.Notice;
import com.uas.platform.b2b.mobile.service.NoticeService;
import com.uas.platform.b2b.model.PurchaseNotice;
import com.uas.platform.core.model.PageInfo;

@Service("mobile.NoticeService")
public class NoticeServiceImpl implements NoticeService {

	@Override
	public Page<Notice> convertNotice(final Page<PurchaseNotice> noticePage) {
		List<Notice> list = new ArrayList<Notice>();
		List<PurchaseNotice> purchaseNotices = noticePage.getContent();
		if (!CollectionUtils.isEmpty(purchaseNotices)) {
			for (PurchaseNotice purchaseNotice : purchaseNotices) {
				list.add(new Notice(purchaseNotice));
			}
		}
		return new PageImpl<Notice>(list, new PageInfo(noticePage.getNumber(), noticePage.getSize()), noticePage.getTotalElements());
	}

	@Override
	public Notice convertNotice(PurchaseNotice notice) {
		return new Notice(notice);
	}

}
