package com.jasamedika.medifirst2000.service.impl;

import com.jasamedika.medifirst2000.converter.base.BaseVoConverter;
import com.jasamedika.medifirst2000.dao.MapProdukPaketDao;
import com.jasamedika.medifirst2000.entities.MapProdukPaket;
import com.jasamedika.medifirst2000.entities.Produk;
import com.jasamedika.medifirst2000.service.MapProdukPaketService;
import com.jasamedika.medifirst2000.vo.MapProdukPaketVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

@Service
@Transactional
public class MapProdukPaketServiceImpl implements MapProdukPaketService {

	@Autowired
	private BaseVoConverter<MapProdukPaketVO, MapProdukPaket> mapProdukPaketConverter;

	@Autowired
	private MapProdukPaketDao mapProdukPaketDao;

	@Override
	public void saveAll(List<MapProdukPaketVO> vos) {
		List<MapProdukPaket> models = new ArrayList<>();
		vos.forEach(vo -> {
			MapProdukPaket model = new MapProdukPaket();
			model = mapProdukPaketConverter.transferVOToModel(vo, model);
			{
				Produk paket = new Produk();
				paket.setId(vo.getPaket().getId());
				model.setPaket(paket);
			}
			{
				Produk produkEntri = new Produk();
				produkEntri.setId(vo.getProdukEntri().getId());
				model.setProdukEntri(produkEntri);
			}
			model.setKdProfile((short) 0);
			model.setIsAktif(true);
			models.add(model);
		});
		mapProdukPaketDao.save(models);
	}
}
