package com.palmnest.service.washcar.service.impl;

import com.palmnest.application.dto.input.ExtraServiceInputDto;
import com.palmnest.model.washcar.OrderExtraService;
import com.palmnest.service.washcar.manager.OrderExtraServiceManager;
import com.palmnest.service.washcar.service.OrderExtraServiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("orderExtraServiceService")
public class OrderExtraServiceServiceImpl implements OrderExtraServiceService {

	@Autowired
	private OrderExtraServiceManager orderExtraServiceManager;

	@Override
	public int saveList(List<ExtraServiceInputDto> list, Long orderId, String userId) throws Exception {
		int count = 0;
		if (list != null && list.size() > 0) {
			for (int i = 0; i < list.size(); i++) {
				ExtraServiceInputDto dto      = list.get(i);
				OrderExtraService    orderExt = new OrderExtraService();
				orderExt.setExtraId(Long.parseLong(dto.getId()));
				orderExt.setOrderId(orderId);
				OrderExtraService oes = orderExtraServiceManager.saveOrderExt(orderExt, userId);
				if (oes != null) {
					count++;
				}
			}
		}
		return count;
	}

}
