package com.ga.core.mapper.commission;

import com.ga.core.vo.commission.MarginSummaryResp;
import com.ga.core.vo.commission.MarginSummarySearchParam;
import com.ga.core.vo.commission.MarginSummaryVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

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

/**
 * margin_summary Mapper — 수지차 집계 (V88)
 */
@Mapper
public interface MarginSummaryMapper {

    MarginSummaryResp selectById(@Param("marginId") Long marginId);

    List<MarginSummaryResp> selectList(MarginSummarySearchParam param);

    /**
     * 정산월 + 설계사(NULL=전체) 단위 수지차 1건 조회.
     * recalc 시 UPSERT 전 존재 여부 확인용.
     */
    MarginSummaryVO selectByMonthAndAgent(@Param("settleMonth") String settleMonth,
                                         @Param("agentId") Long agentId);

    /** 정산월 전체 수입수수료 합 (income_commission_ledger, CANCELLED 제외). */
    BigDecimal sumIncomeByMonth(@Param("settleMonth") String settleMonth);

    /** 정산월 지급 합 (settle_master.net_amount). agentId NULL=전체. */
    BigDecimal sumPayoutByMonth(@Param("settleMonth") String settleMonth,
                                @Param("agentId") Long agentId);

    int insert(MarginSummaryVO vo);

    int update(MarginSummaryVO vo);

    int delete(@Param("marginId") Long marginId);
}
