package com.bb.dao;

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

import jakarta.validation.Valid;

import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import com.bb.model.CashParam;
import com.bb.model.Credit;
import com.bb.model.CreditPoint;
import com.bb.model.CreditPointSearch;
import com.bb.model.CreditSearchVO;
import com.bb.model.Insure;
import com.bb.model.SiteSearch;

@Repository("creditDao")
public class CreditDaoImpl implements CreditDao  {
	
	  /** 메인DB 연결 */
    @Autowired @Qualifier("sqlSessionMain")
    protected SqlSession sqlSession;
 
    /** 서브DB 연결 */
    @Autowired @Qualifier("sqlSessionSub")
    protected SqlSession sqlSessionSub;

	@Override
	public void insertCredit(Credit credit) {
		sqlSession.insert("insertCredit", credit);
	}
	
	@Override
	public void insertCreditByCash(Credit credit) {
		sqlSession.insert("insertCreditByCash", credit);
	}

	@Override
	public void setSiteCreditUpdate(HashMap param) {
		sqlSession.update("setSiteCreditUpdate", param);
		
	}

	@Override
	public int getCreditListCnt(SiteSearch search) {
		// TODO Auto-generated method stub
		return sqlSession.selectOne("getCreditListCnt", search);
	}

	@Override
	public List<HashMap> getCreditList(SiteSearch search) {
		// TODO Auto-generated method stub
		return sqlSession.selectList("getCreditList", search);
	}

	@Override
	public int getSiteTranListCnt(SiteSearch search) {
		// TODO Auto-generated method stub
		return sqlSession.selectOne("getSiteTranListCnt", search);
	}

	@Override
	public List<HashMap> getSiteTranList(SiteSearch search) {
		// TODO Auto-generated method stub
		return sqlSession.selectList("getSiteTranList", search);
	}

	@Override
	public void updateStatus(Credit credit) {
		// TODO Auto-generated method stub
		sqlSession.update("updateStatus", credit);
	}

	@Override
	public int getPointListCnt(SiteSearch search) {
		// TODO Auto-generated method stub
		return sqlSession.selectOne("getPointListCnt", search);
	}

	@Override
	public List<HashMap> getPointList(SiteSearch search) {
		return sqlSession.selectList("getPointList", search);
	}

	@Override
	public int getSiteBetListCnt(SiteSearch search) {		
		return sqlSession.selectOne("getSiteBetListCnt", search);
	}

	@Override
	public List<HashMap> getSiteBetList(SiteSearch search) {
		return sqlSession.selectList("getSiteBetList", search);
	}

	@Override
	public void updateInsureStatus(Insure insure) {
		// TODO Auto-generated method stub
		sqlSession.update("updateInsureStatus", insure);
	}

	@Override
	public void insertInsure(Insure insure) {
		// TODO Auto-generated method stub
		sqlSession.insert("insertInsure", insure);
	}

	@Override
	public HashMap getMyInsureInfo(int siteIdx) {
		return sqlSession.selectOne("getMyInsureInfo", siteIdx);
	}
	
	@Override
	public HashMap getMyRateInfo(int siteIdx) {
		return sqlSession.selectOne("getMyRateInfo", siteIdx);
	}

	@Override
	public int getInsureListCnt(SiteSearch search) {
		return sqlSession.selectOne("getInsureListCnt", search);
	}

	@Override
	public List<HashMap> getInsureList(SiteSearch search) {
		return sqlSession.selectList("getInsureList", search);
	}

	@Override
	public HashMap getCreditSumToday(SiteSearch search) {
		// TODO Auto-generated method stub
		return  sqlSession.selectOne("getCreditSumToday", search);
	}

	@Override
	public void updateSetStatus(Credit credit2) {
		// TODO Auto-generated method stub
		sqlSession.update("updateSetStatus", credit2);
	}

	@Override
	public void updateCreditYn(Credit credit) {
		// TODO Auto-generated method stub
		sqlSession.update("updateCreditYn", credit);
	}
	
	@Override
	public String getRoundIdByGsoft(String refId) {
		// TODO Auto-generated method stub
		return  sqlSessionSub.selectOne("getRoundIdByGsoft", refId);
	}

	@Override
	public void insertCreditAiAo(Credit credit) {
		// TODO Auto-generated method stub
		sqlSession.insert("insertCreditAiAo", credit);
	}

	@Override
	public void insertCreditPoint(HashMap pointParam) {
		// TODO Auto-generated method stub
		sqlSession.insert("insertCreditPoint", pointParam);
	}

	@Override
	public int insertPoint(CreditPoint point) {
		// TODO Auto-generated method stub
		return sqlSession.insert("insertPoint", point);
	}

	@Override
	public int checkRequestTime(Credit credit) {
		// TODO Auto-generated method stub
		return sqlSession.selectOne("checkRequestTime", credit);
	}

	@Override
	public int getCashInOutListCnt(CashParam param) {
		// TODO Auto-generated method stub
		return sqlSessionSub.selectOne("getCashInOutListCnt", param);
	}

	@Override
	public List<HashMap> getCashInOutList(CashParam param) {
		// TODO Auto-generated method stub
		return sqlSessionSub.selectList("getCashInOutList", param);
	}

	@Override
	public int getTransCreditListCnt(CreditSearchVO search) {
		// TODO Auto-generated method stub
		return sqlSessionSub.selectOne("getTransCreditListCnt", search);
	}

	@Override
	public List<HashMap<String, Object>> getTransCreditList(CreditSearchVO search) {
		// TODO Auto-generated method stub
		return sqlSessionSub.selectList("getTransCreditList", search);
	}

	@Override
	public int getTotalTransactionListCnt(CreditSearchVO search) {
		// TODO Auto-generated method stub
		return sqlSessionSub.selectOne("getTotalTransactionListCnt", search);
	}

	@Override
	public List<HashMap<String, Object>> getTotalTransactionList(CreditSearchVO search) {
		// TODO Auto-generated method stub
		return sqlSessionSub.selectList("getTotalTransactionList", search);
	}

	@Override
	public int getCreditPointListCnt(@Valid CreditPointSearch search) {
		// TODO Auto-generated method stub
		return sqlSessionSub.selectOne("getCreditPointListCnt", search);
	}

	@Override
	public List<HashMap<String, String>> getCreditPointList(@Valid CreditPointSearch search) {
		// TODO Auto-generated method stub
		return sqlSessionSub.selectList("getCreditPointList", search);
	}

	@Override
	public int getCreditBetListCnt(@Valid CreditPointSearch search) {
		// TODO Auto-generated method stub
		return sqlSessionSub.selectOne("getCreditBetListCnt", search);
	}

	@Override
	public List<HashMap<String, String>> getCreditBetList(@Valid CreditPointSearch search) {
		// TODO Auto-generated method stub
		return sqlSessionSub.selectList("getCreditBetList", search);
	}

	@Override
	public int getStatCreditListCnt(SiteSearch search) {
		return sqlSessionSub.selectOne("getStatCreditListCnt", search);
	}

	@Override
	public List<HashMap> getStatCreditList(SiteSearch search) {
		return sqlSessionSub.selectList("getStatCreditList", search);
	}

	@Override
	public HashMap getStatCreditTotal(SiteSearch search) {
		// TODO Auto-generated method stub
		return sqlSessionSub.selectOne("getStatCreditTotal", search);
	}

	@Override
	public void updateSubCredit(Credit credit) {
		// TODO Auto-generated method stub
		sqlSession.update("updateSubCredit", credit);
	}

}
