package com.palmnest.dao.notice.impl;

import org.springframework.stereotype.Repository;

import com.palmnest.dao.hibernate.GenericDaoHibernate;
import com.palmnest.dao.notice.AppNoticeContentDao;
import com.palmnest.model.notice.AppNoticeContentModel;

@Repository("appNoticeContentDao")
public class AppNoticeContentDaoImpl extends GenericDaoHibernate<AppNoticeContentModel, Integer> implements AppNoticeContentDao {
	public AppNoticeContentDaoImpl() {
		super(AppNoticeContentModel.class);

	}

	@Override
	public AppNoticeContentModel findByIdAndImage(Integer id, String image,
												  int type, int source) {
		if (1 == source) {
			String sql = "from AppNoticeContentModel where isEnabled=1 and sourceId=? and type=? and oldImage=? ";
			return (AppNoticeContentModel) getSession()
					.createQuery(sql)
					.setInteger(0, id)
					.setInteger(1, type)
					.setString(2, image)
					.setMaxResults(1)
					.uniqueResult();
		} else {
			String sql = "from AppNoticeContentModel where isEnabled=1 and sourceId=? and type=? and newImage=? ";
			return (AppNoticeContentModel) getSession()
					.createQuery(sql)
					.setInteger(0, id)
					.setInteger(1, type)
					.setString(2, image)
					.setMaxResults(1)
					.uniqueResult();
		}

	}
}
