package com.m2pool.lease.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.m2pool.common.datasource.annotation.MiningDB;
import com.m2pool.lease.dto.v2.*;
import com.m2pool.lease.entity.LeaseOrderMining;
import com.m2pool.lease.netty.message.ClientConfigurationMining;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 挖矿中订单 Mapper 接口
 * </p>
 *
 * @author yyb
 * @since 2025-12-02
 */
@Mapper
public interface LeaseOrderMiningMapper extends BaseMapper<LeaseOrderMining> {
    /**
     * 批量插入
     *
     * @param orderMiningList
     * @return
     */
    int insertBatch(@Param("list") List<LeaseOrderMining> orderMiningList);


    /**
     * 获取矿池正在挖矿中的信息
     *
     * @param clientConfigurationMining
     * @return
     */
    int updateOrderMining(@Param("userEmail") String userEmail,@Param("clientConfigurationMining") ClientConfigurationMining clientConfigurationMining);

    /**
     * 获取用户购买的机器列表
     * @param userEmail
     * @return
     */
    List<PurchasedMachineListDto> getPurchasedItems(@Param("userEmail") String userEmail);

    /**
     * 根据id获取用户购买的机器信息
     * @param id
     * @return
     */
    MiningConfigInfoDto getPurchasedInfo(@Param("id") Long id);


    /**
     * 获取最近一次的算力
     * @param list
     * @return
     */
    @MiningDB
    @MapKey("miner")
    Map<String,MiningHashrateInfoDto> getRecentlyHashrate(@Param("pool") String pool,@Param("wallet") String wallet,@Param("coin") String coin,@Param("list") List<PurchasedMachineDto> list);


    /**
     * 获取最近24小时的算力
     * @return
     */
    @MiningDB
    List<RealHashrateInfoDto> getRecently24HourHashrate(@Param("list") List<PurchasedMachineListDto> list,@Param("tableName") String tableName,@Param("now") Date now);


    /**
     * 根据orderId集合获取挖矿中的信息
     * @param orderIds
     * @return
     */
    List<PurchasedMachineListDto> getMiningInfoByOrderId(@Param("orderIds") List<Long> orderIds);


    /**
     * 检查是否存在挖矿中矿工
     * @param list
     * @return
     */
    List<OrderMiningInfoDto> checkMiningMinersExist(@Param("list") List<OrderMiningInfoDto> list);


    /**
     * 获取用户购买的矿机信息
     * @param info
     * @return
     */
    List<PurchasedMachineDto> getPurchasedMachineInfo(@Param("info") MiningConfigInfoDto info);
}
