package com.ga.core.mapper.settle;

import com.ga.core.vo.settle.AgentDeductionResp;
import com.ga.core.vo.settle.AgentDeductionSearchParam;
import com.ga.core.vo.settle.AgentDeductionVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

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

@Mapper
public interface AgentDeductionMapper {
    List<AgentDeductionResp> selectList(AgentDeductionSearchParam param);
    AgentDeductionResp selectDetailById(@Param("deductionId") Long deductionId);
    AgentDeductionVO selectById(@Param("deductionId") Long deductionId);

    int insert(AgentDeductionVO vo);
    int update(AgentDeductionVO vo);
    int updateStatus(@Param("deductionId") Long deductionId, @Param("status") String status);

    /** 정산월 + 설계사의 PENDING 차감 합계 */
    BigDecimal sumPendingByAgent(@Param("agentId") Long agentId,
                                 @Param("settleMonth") String settleMonth);

    /** 정산월 전체 PENDING 목록 (배치용) */
    List<AgentDeductionVO> selectPendingByMonth(@Param("settleMonth") String settleMonth);

    /** 설계사의 PENDING 목록 (단건 차감 적용용) */
    List<AgentDeductionVO> selectPendingByAgent(@Param("agentId") Long agentId,
                                                @Param("settleMonth") String settleMonth);

    /** 일괄 상태 전이 */
    int updateStatusBatch(@Param("deductionIds") List<Long> deductionIds,
                          @Param("status") String status);

    /** 중복 검증 */
    int countByAgentMonthType(@Param("agentId") Long agentId,
                              @Param("settleMonth") String settleMonth,
                              @Param("deductionType") String deductionType);
}
