package com.ga.core.mapper.commission;

import com.ga.core.vo.commission.BranchMgrAllowanceLedgerResp;
import com.ga.core.vo.commission.BranchMgrAllowanceLedgerSearchParam;
import com.ga.core.vo.commission.BranchMgrAllowanceLedgerVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

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

/**
 * branch_mgr_allowance_ledger Mapper — 지점장수당 원장 (V94)
 */
@Mapper
public interface BranchMgrAllowanceLedgerMapper {

    BranchMgrAllowanceLedgerResp selectById(@Param("ledgerId") Long ledgerId);

    List<BranchMgrAllowanceLedgerResp> selectList(BranchMgrAllowanceLedgerSearchParam param);

    /** 지점장 + 정산월 수당 합계 */
    BigDecimal sumAllowanceByManagerAndMonth(@Param("managerAgentId") Long managerAgentId,
                                            @Param("settleMonth") String settleMonth);

    /** 정산월 기준 지점장별 순수당 합계(allowance_amount - COALESCE(clawback_amount,0)) — settle_master 집계 배치 용도 */
    List<Map<String, Object>> aggregateByAgent(@Param("settleMonth") String settleMonth);

    int insert(BranchMgrAllowanceLedgerVO vo);

    int updateStatus(@Param("ledgerId") Long ledgerId, @Param("status") String status);

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