package com.sonic.lion.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sonic.lion.domain.entity.WithdrawRequest;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

public interface WithdrawRequestDao extends BaseMapper<WithdrawRequest> {

    // 这里都是换算成buff的
    @Select("select IFNULL(SUM(amount),0) from t_withdraw_request where src_account_id = #{uid} AND status=0 AND coin_type = #{coinType}")
    int totalRequest(@Param("uid") Long srcAccountId, @Param("coinType") String coinType);

    @Select("select count(1)  from account_buff where withdrawable_income >= #{amount}  AND uid = #{uid}")
    int checkBuffWithdrawAble(@Param("uid") Long srcAccountId, @Param("amount") Long amount);

    @Select("select count(1)  from account_ecoin where withdrawable_income >= #{amount}  AND uid = #{uid}")
    int checkEcoinWithdrawAble(@Param("uid") Long srcAccountId, @Param("amount") Long amount);

    @Select("select * from t_withdraw_request where status =0 AND create_time <= #{createTime} ")
    List<WithdrawRequest> getUnPaidRequest(@Param("createTime") LocalDateTime createTime);

    @Update("update t_withdraw_request set status = 1 where id=#{id}")
    int updateStatus(@Param("id") Long id);

}
