package com.uas.platform.b2b.mobile.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;

import com.uas.platform.b2b.mobile.dao.AdvancedSettingsDao;
import com.uas.platform.b2b.mobile.model.AdvancedSettings;
import com.uas.platform.b2b.mobile.service.AdvancedSettingsService;

@Service
public class AdvancedSettingsServiceImpl implements AdvancedSettingsService {

	@Autowired
	private AdvancedSettingsDao advancedSettingsDao;

	@Override
	public ModelMap saveAdvancedSettings(AdvancedSettings advancedSettings) {
		ModelMap map = new ModelMap();
		AdvancedSettings adv = advancedSettingsDao.getSettingsByEnuu(advancedSettings.getEnuu());
		if (adv != null) {
			adv.setAutosign(advancedSettings.getAutosign());
			adv.setEarlyoff(advancedSettings.getEarlyoff());
			adv.setEmcode(advancedSettings.getEmcode());
			adv.setEnuu(advancedSettings.getEnuu());
			adv.setLatetime(advancedSettings.getLatetime());
			adv.setNonclass(advancedSettings.getNonclass());
			adv.setOverlatetime(advancedSettings.getOverlatetime());
			advancedSettingsDao.save(adv);
			map.put("success", true);
		} else {
			advancedSettings = advancedSettingsDao.save(advancedSettings);
			if (advancedSettings.getId() != null) {
				map.put("success", true);
			} else {
				map.put("success", false);
			}
		}
		return map;
	}

	@Override
	public AdvancedSettings getSettingsByEnuu(Long enuu) {
		return advancedSettingsDao.getSettingsByEnuu(enuu);
	}

}
