package com.jasamedika.medifirst2000.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.lang.math.RandomUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.jpa.JpaSystemException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


	

import com.jasamedika.medifirst2000.exception.ServiceVOException;
import com.jasamedika.medifirst2000.service.PekerjaanService;
import com.jasamedika.medifirst2000.util.CommonUtil;
import com.jasamedika.medifirst2000.entities.Pekerjaan;
import com.jasamedika.medifirst2000.vo.PekerjaanVO;
import com.jasamedika.medifirst2000.converter.BaseConverterImpl;
import com.jasamedika.medifirst2000.dao.PekerjaanDao;

/**
 * Implement class for PekerjaanService
 * 
 * @author Generator
 * @param <T>
 */
@Service("pekerjaanService")
public class PekerjaanServiceImpl extends BaseVoServiceImpl implements PekerjaanService 
{	
	@Autowired
	private BaseConverterImpl<PekerjaanVO,Pekerjaan>pekerjaanConverter;
	
	@Autowired
	private PekerjaanDao pekerjaanDao;


	@Override
	public Map<String, Object> savePekerjaan(PekerjaanVO vo) {
		Map<String, Object> result = new HashMap<String, Object>();
		Pekerjaan model = new Pekerjaan();
		model = pekerjaanConverter.transferVOToModel(vo,model);

		String randomId = RandomStringUtils.randomAlphanumeric(32);
		
		Byte nomor = (Byte)this.pekerjaanDao.getMaxPekerjaan();
		model.setqPekerjaan(nomor);
		model.setKdPekerjaan(nomor);
		model.setNoRec(randomId);
	
		Pekerjaan resultDomain = pekerjaanDao.save(model);
		if (CommonUtil.isNotNullOrEmpty(resultDomain)) {
			result.put("noRec", resultDomain.getNoRec());
		}

		return result;
	}


	@Override
	public Map<String, Object> getPekerjaan() {
		Map<String, Object> result = new HashMap<>();
		result.put("data", this.pekerjaanDao.getPekerjaan());
		return result;
	}
	
	
}