package com.ga.core.mapper.commission;

import com.ga.core.vo.commission.AdvancePaymentResp;
import com.ga.core.vo.commission.AdvancePaymentSearchParam;
import com.ga.core.vo.commission.AdvancePaymentVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

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

/**
 * advance_payment Mapper — 선지급금 마스터 (V117)
 */
@Mapper
public interface AdvancePaymentMapper {

    AdvancePaymentResp selectById(@Param("advanceId") Long advanceId);

    List<AdvancePaymentResp> selectList(AdvancePaymentSearchParam param);

    int insert(AdvancePaymentVO vo);

    int update(AdvancePaymentVO vo);

    int delete(@Param("advanceId") Long advanceId);

    /**
     * 설계사의 미상환 잔액 합계.
     * status IN ('OUTSTANDING','PARTIAL') 대상 SUM(balance).
     */
    BigDecimal outstandingByAgent(@Param("agentId") Long agentId);

    /**
     * 설계사의 FIFO 상계 대상 선지급금 목록.
     * status IN ('OUTSTANDING','PARTIAL') ORDER BY advance_month ASC, advance_id ASC.
     */
    List<AdvancePaymentVO> selectOutstandingFifo(@Param("agentId") Long agentId);
}
