package com.palmnest.service.notice.impl;

import com.palmnest.application.bean.Page;
import com.palmnest.dao.notice.WxtemplateMessageConfigDao;
import com.palmnest.model.notice.WxtemplateMessageConfigModel;
import com.palmnest.service.impl.GenericManagerImpl;
import com.palmnest.service.notice.WxtemplateMessageConfigManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("wxtemplateMessageConfigManager")
public class WxtemplateMessageConfigManagerImpl extends GenericManagerImpl<WxtemplateMessageConfigModel, Integer> implements WxtemplateMessageConfigManager {

	private WxtemplateMessageConfigDao wxtemplateMessageConfigDao;

	@Autowired
	public void setWxtemplateMessageConfigDao(
			WxtemplateMessageConfigDao wxtemplateMessageConfigDao) {
		this.wxtemplateMessageConfigDao = wxtemplateMessageConfigDao;
		this.dao = wxtemplateMessageConfigDao;
	}

	@Override
	public String saveOrUpdate(WxtemplateMessageConfigModel wxtemplateMessageConfigModel) {

		String isSuccess = "fail";
		if (wxtemplateMessageConfigModel.getId() == 0 || wxtemplateMessageConfigModel.getId() == null) {
			WxtemplateMessageConfigModel model = wxtemplateMessageConfigDao.save(wxtemplateMessageConfigModel);
			if (model != null) {
				isSuccess = "success";
			}
		} else {
			try {
				wxtemplateMessageConfigDao.updateObj(wxtemplateMessageConfigModel);
				isSuccess = "success";
			} catch (Exception e) {

				isSuccess = "fail";
			}
		}
		return isSuccess;
	}

	@Override
	public String delByTemplateMessageId(Integer templateMessageId) throws Exception {

		wxtemplateMessageConfigDao.delByTemplateMessageId(templateMessageId);
		return "success";
	}


	@Override
	public Page findAll(int id) throws Exception {
		return wxtemplateMessageConfigDao.findAll(id);
	}

	@Override
	public List<WxtemplateMessageConfigModel> getWxTemplConfigByTypeId(
			int typeId) throws Exception {
		return wxtemplateMessageConfigDao.getWxTemplConfigByTypeId(typeId);
	}

	@Override
	public List<WxtemplateMessageConfigModel> getWxTemplConfigByTypeId(
			int typeId, int msgId) throws Exception {
		return wxtemplateMessageConfigDao.getWxTemplConfigByTypeId(typeId, msgId);
	}


	@Override
	public Page findTemplateByTempId(int tempId) throws Exception {
		return wxtemplateMessageConfigDao.findTemplateByTempId(tempId);
	}

	@Override
	public List<WxtemplateMessageConfigModel> findTemplateByTempIdAndTempMsgId(int tempId, int tempMsgId) throws Exception {
		return wxtemplateMessageConfigDao.findTemplateByTempIdAndTempMsgId(tempId, tempMsgId);
	}

	@Override
	public List<WxtemplateMessageConfigModel> findTemplateByTempIdDefault(int tempId) throws Exception {
		return wxtemplateMessageConfigDao.findTemplateByTempIdDefault(tempId);
	}


	@Override
	public String delByTemplateId(Integer templateMessageId) throws Exception {
		wxtemplateMessageConfigDao.delByTemplateId(templateMessageId);
		return "success";
	}

	@Override
	public Page findTemplateByTempIdFromLibrary(int tempId) throws Exception {
		return wxtemplateMessageConfigDao.findTemplateByTempIdFromLibrary(tempId);
	}

}
