package com.dora.mapper;

import com.dora.entity.FanPromotionCommission;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

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

/**
 * 粉丝推广提成Mapper接口
 */
@Mapper
public interface FanPromotionCommissionMapper {

    /**
     * 根据推广人ID查询提成记录
     */
    List<FanPromotionCommission> selectByPromoterId(@Param("promoterId") Long promoterId);

    /**
     * 根据推广人ID查询已结算的提成总额
     */
    BigDecimal sumSettledCommissionByPromoterId(@Param("promoterId") Long promoterId);

    /**
     * 根据推广人ID查询待结算的提成总额
     */
    BigDecimal sumPendingCommissionByPromoterId(@Param("promoterId") Long promoterId);

    /**
     * 插入推广分成记录
     */
    int insert(FanPromotionCommission commission);

    /**
     * 更新分成状态
     */
    int updateStatus(@Param("id") Long id, @Param("status") Integer status, @Param("settledAt") java.time.LocalDateTime settledAt);

    /**
     * 检查订单是否已有推广分成记录
     */
    Boolean existsByOrderId(@Param("orderId") Long orderId);

    /**
     * 根据推广人ID查询推广分成详情（包含关联信息）
     */
    List<com.dora.dto.UserBalanceDto.PromotionIncomeItem> selectPromotionIncomeDetailsByPromoterId(@Param("promoterId") Long promoterId);
} 