package com.dora.mapper;

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

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 用户余额Mapper接口
 */
@Mapper
public interface UserBalanceMapper {

    /**
     * 根据用户ID查询余额
     */
    UserBalance selectByUserId(@Param("userId") Long userId);

    /**
     * 插入用户余额记录
     */
    int insert(UserBalance userBalance);

    /**
     * 更新用户余额
     */
    int updateBalance(@Param("userId") Long userId, 
                     @Param("balance") BigDecimal balance,
                     @Param("totalIncome") BigDecimal totalIncome,
                     @Param("totalWithdrawn") BigDecimal totalWithdrawn,
                     @Param("frozenAmount") BigDecimal frozenAmount);

    /**
     * 增加用户余额
     */
    int increaseBalance(@Param("userId") Long userId, 
                       @Param("amount") BigDecimal amount,
                       @Param("totalIncome") BigDecimal totalIncome);

    /**
     * 减少用户余额
     */
    int decreaseBalance(@Param("userId") Long userId, 
                       @Param("amount") BigDecimal amount,
                       @Param("totalWithdrawn") BigDecimal totalWithdrawn);

    /**
     * 冻结用户余额
     */
    int freezeBalance(@Param("userId") Long userId, 
                     @Param("amount") BigDecimal amount);

    /**
     * 解冻用户余额
     */
    int unfreezeBalance(@Param("userId") Long userId, 
                       @Param("amount") BigDecimal amount);

    // ====== 仪表盘统计相关 ======

    /**
     * 统计总收入
     */
    BigDecimal sumTotalIncome();

    /**
     * 统计今日收入
     */
    BigDecimal sumTodayIncome(@Param("today") LocalDateTime today);

    /**
     * 统计用户余额总和
     */
    BigDecimal sumTotalBalance();
} 