package com.eactive.eai.rms.common.board;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.eactive.eai.rms.common.base.SqlMapClientForMetaTemplateDao;

@Repository("boardDao")
@SuppressWarnings({"deprecation","unchecked"})
//public class BoardDao extends SqlMapClientForMonitoringTemplateDao {
public class BoardDao extends SqlMapClientForMetaTemplateDao {
	public int selectListCount(HashMap<String, Object> param) throws Exception {
    	return (Integer)template.queryForObject("Board.selectListCount", param);
    }	

	public List<Map<String, Object>> selectList(HashMap<String, Object> param) throws Exception {
		List<Map<String, Object>>  itemList = (List<Map<String, Object>>)template.queryForList("Board.selectList", param);
    	
    	for(Map<String, Object> row: itemList) {
    		row.put("expended", "true");
    		 
    		int level = (int)row.get("LVL")-1;
    		
    		// change to 0 index
    		row.put("level", ""+level);
    		
    		row.put("isLeaf", "true");
//    		if(level > 0) {
//    			row.put("isLeaf", "true");
//    		}
//    		else {
//    			row.put("isLeaf", "false");
//    		}
    		
    	}
    	return itemList;
    }	
	
	public List<Map<String, Object>> selectFIleList(HashMap<String, Object> param) throws Exception {
		List<Map<String, Object>>  itemList = (List<Map<String, Object>>)template.queryForList("Board.selectFileList", param);
    	return itemList;
    }	
	
	public String selectSeqNo(HashMap param) throws Exception {
    	return (String)template.queryForObject("Board.selectSeqNo", param);
    }
	public HashMap selectNextLevelNo(HashMap param) throws Exception {
    	return (HashMap)template.queryForObject("Board.selectNextLevelNo", param);
    }
	
	public HashMap selectDetail(HashMap param) throws Exception {
    	return (HashMap) template.queryForObject("Board.selectDetail", param);
    }
	
	public void insert(HashMap<String, Object> paramMap) throws Exception{
        this.template.insert("Board.insert", paramMap);
    }      
    
    public void update(HashMap<String, Object> paramMap) throws Exception{
        this.template.update("Board.update", paramMap);
    }
    
    public void updateReadCount(HashMap<String, Object> paramMap) throws Exception{
        this.template.update("Board.updateReadCnt", paramMap);
    }
    
    public void updateAnswer(HashMap<String, Object> paramMap) throws Exception{
        this.template.update("Board.updateAnswer", paramMap);
    }
    
    public void delete(HashMap<String, Object> paramMap) throws Exception{
        this.template.delete("Board.delete", paramMap);
    }
}