package com.ga.core.mapper.ledger;

import com.ga.core.vo.ledger.LedgerExcelVO;
import com.ga.core.vo.ledger.LedgerResp;
import com.ga.core.vo.ledger.LedgerSearchParam;
import com.ga.core.vo.ledger.LedgerVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.cursor.Cursor;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@Mapper
public interface MaintainLedgerMapper {
    List<LedgerResp> selectList(LedgerSearchParam param);
    LedgerResp selectDetailById(@Param("ledgerId") Long ledgerId);
    LedgerVO selectById(@Param("ledgerId") Long ledgerId);
    Cursor<LedgerExcelVO> selectCursorForExcel(LedgerSearchParam param);
    int insert(LedgerVO vo);
    int batchInsert(@Param("list") List<LedgerVO> list);
    int update(LedgerVO vo);
    int deleteBySettleMonth(@Param("settleMonth") String settleMonth);
    List<Map<String, Object>> aggregateByAgent(@Param("settleMonth") String settleMonth);
    BigDecimal sumByMonth(@Param("settleMonth") String settleMonth);
    BigDecimal sumByAgentMonth(@Param("agentId") Long agentId,
                               @Param("settleMonth") String settleMonth);

    /** 정산월 + 설계사 + 보험종류 합계 (오버라이드 insurance_type_cond 적용용) */
    BigDecimal sumByAgentMonthAndType(@Param("agentId") Long agentId,
                                      @Param("settleMonth") String settleMonth,
                                      @Param("insuranceType") String insuranceType);

    /** 계약별 유지 원장 수수료 합산 (1200%룰 누적 검증용) */
    BigDecimal sumByContract(@Param("contractId") Long contractId);
}
