package com.m2pool.pool.mapper;


import com.m2pool.common.datasource.annotation.DistributionDB;
import com.m2pool.common.datasource.annotation.HashRateDB;
import com.m2pool.common.datasource.annotation.InfoDB;
import com.m2pool.pool.dto.*;
import com.m2pool.pool.entity.BlockInfo;
import com.m2pool.pool.entity.PoolPower;
import com.m2pool.pool.vo.DateValueVo;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * @Description TODO
 * @Date 2022/8/30 17:47
 * @Author 杜懿
 */
@InfoDB
public interface PoolMapper {

        @HashRateDB
        public PoolInfoDto getPoolInfoByCoin(@Param("table") String table);

        @HashRateDB
        public Double  getNowPoolDailyPower(@Param("table") String table);

        @HashRateDB
        public Double getNowPoolPower(@Param("table") String table);

        public List<PowerLineDto> get30mPoolPowerList(@Param("table") String table,@Param("startDate") Date startDate,@Param("endDate") Date endDate);

        public List<PowerLineDto> getDailyPoolPowerList(@Param("table") String table,@Param("startDate") Date startDate,@Param("endDate") Date endDate);

        public List<PowerLineDto> getHourPoolPowerList(@Param("table") String table);
        public List<PowerLineDto> getHourNetPowerList(@Param("table") String table);

        public List<BlockInfoDto> getGRSBlockInfoList();

        public List<BlockInfoDto> getMonaBlockInfoList();

        public List<BlockInfoDto> getDgbQubitBlockInfoList();

        public List<BlockInfoDto> getDgbSkeinBlockInfoList();

        public List<BlockInfoDto> getDGBODOBlockInfoList();

        public List<BlockInfoDto> getDgbQubitA10BlockInfoList();

        public List<BlockInfoDto> getDgbSkeinA10BlockInfoList();

        public List<BlockInfoDto> getDGBODOB20BlockInfoList();

        public List<BlockInfoDto> getRXDBlockInfoList();

        public List<BlockInfoDto> getNEXABlockInfoList();

        public List<BlockInfoDto> getALPHBlockInfoList();

        public List<BlockInfoDto> getENXBlockInfoList();

        public List<BlockInfoDto> getMONEROBlockInfoList();

        public List<BlockInfoDto> getXtmBlockInfoList();

        @DistributionDB
        public List<BlockInfoDto> getNewNEXABlockInfoList(@Param("date") String date);

        @DistributionDB
        public List<BlockInfoDto> getNewGRSBlockInfoList(@Param("date") String date);

        @DistributionDB
        public List<BlockInfoDto> getNewMONABlockInfoList(@Param("date") String date);

        @DistributionDB
        public List<BlockInfoDto> getNewDGBQBlockInfoList(@Param("date") String date);

        @DistributionDB
        public List<BlockInfoDto> getNewDGBSBlockInfoList(@Param("date") String date);

        @DistributionDB
        public List<BlockInfoDto> getNewDGBOBlockInfoList(@Param("date") String date);

        @DistributionDB
        public List<BlockInfoDto> getNewRXDBlockInfoList(@Param("date") String date);

        @DistributionDB
        public List<BlockInfoDto> getNewALPHBlockInfoList(@Param("date") String date);

        @DistributionDB
        public List<BlockInfoDto> getNewENXBlockInfoList(@Param("date") String date);

        @DistributionDB
        public List<BlockInfoDto> getNewMONEROBlockInfoList(@Param("date") String date);

        @DistributionDB
        public List<BlockInfoDto> getNewXtmBlockInfoList(@Param("date") String date);


        @HashRateDB
        public List<MinerDataDto> getMinerInfoList(@Param("table") String table);

        //public List<MinerDataDto> get24hMinerInfoList(@Param("table") String table);

        public List<PowerLineDto> get30mAccountPowerListByAccount(@Param("table") String table, @Param("user") String user);



        public List<PowerLineDto> getDailyAccountPowerListByAccount(@Param("table") String table, @Param("user") String user);

        public List<PowerLineDto> get24hAccountPowerListByAccount(@Param("table") String table, @Param("user") String user);

        //todo 考虑删除
        public List<MinerDataDto> getDailyPoolPowerDistributionList(@Param("table") String table);

        //todo 考虑删除
        public List<MinerDataDto> getDailyAccountPowerDistributionList(@Param("table") String table, @Param("user") String user);

        public List<PowerLineDto> getMinerPowerList(@Param("table") String table, @Param("user") String user, @Param("miner") String miner);

        //todo 考虑删除
        public List<MinerDataDto> getDailyMinerPowerDistributionList(@Param("table") String table, @Param("user") String user, @Param("miner") String miner);

        @HashRateDB
        public List<MinerDataDto> getHourMinerDataList(@Param("table") String table,@Param("now") String now);

        @HashRateDB
        public List<MinerDataDto> getDailyMinerDataList(@Param("table") String table,@Param("now") String now);

        //todo 考虑删除
        public List<MinerDataDto> getUserHourMinerDataList(@Param("table") String table);

        //todo 考虑删除
        public List<MinerDataDto> getUserDailyMinerDataList(@Param("table") String table);

        //从网站的算力总表拿大于date的数据条数
        public int getLastDataTime(@Param("table") String table,@Param("date") String date);

        //批量写入算力数据
        public boolean batchInsertMhsDataToDB(@Param("table") String table,@Param("list") List<MinerDataInsertDBDto> list);

        public boolean batchInsertUserMhsDateToDB(@Param("table") String table,@Param("list") List<MinerDataInsertDBDto> list);

        //public boolean batchInsertUserMhsDataToDB(@Param("table") String table,@Param("list") List<MinerDataInsertDBDto> list);

        //写入全网算力数据 30m
        public boolean insertNetPower(@Param("table") String table,@Param("date") String date,@Param("vo") DateValueVo vo);

        //写入币价数据 30m
        public boolean insertPrice(@Param("table") String table,@Param("date") String date,@Param("vo") DateValueVo vo);

        public BigDecimal selectPrice(@Param("coin") String coin);

        //@Pool2DB
        //public boolean insertMhsDataToDB(@Param("table") String table,@Param("list") List<MinerDataDto> list);
        //报块信息表
        public boolean batchInsertNexaPoolBlkToDB(@Param("list") List<BlockInfoDto> list);

        public boolean batchInsertGRSPoolBlkToDB(@Param("list") List<BlockInfoDto> list);

        public boolean batchInsertMONAPoolBlkToDB(@Param("list") List<BlockInfoDto> list);

        public boolean batchInsertDGBOPoolBlkToDB(@Param("list") List<BlockInfoDto> list);

        public boolean batchInsertDGBQPoolBlkToDB(@Param("list") List<BlockInfoDto> list);

        public boolean batchInsertDGBSPoolBlkToDB(@Param("list") List<BlockInfoDto> list);

        public boolean batchInsertRXDPoolBlkToDB(@Param("list") List<BlockInfoDto> list);

        public boolean batchInsertALPHPoolBlkToDB(@Param("list") List<BlockInfoDto> list);

        public boolean batchInsertENXPoolBlkToDB(@Param("list") List<BlockInfoDto> list);

        public boolean batchInsertMONEROPoolBlkToDB(@Param("list") List<BlockInfoDto> list);

        //todo 矿池统计数据入库
        public boolean insertPoolPower(@Param("table") String table,@Param("vo") PoolPower vo);

        public BigDecimal getPoolTodayTotalPower(@Param("coin") String coin, @Param("date") String date);

        public List<UserPowerDto> getUserTodayTotalPower(@Param("coin") String coin, @Param("date") String date);

        public List<DateBigDecimalDto> getDailyPoolPower(@Param("coin") String coin);

        public List<DateBigDecimalDto> getDailyNetPower(@Param("coin") String coin);

        public BigDecimal getAvgNetPower(@Param("coin") String coin, @Param("date") String date);
        //todo 分配数据入库  目的:整合主库分库

        public List<OfflineUserMinerDto> getOfflineList(@Param("table") String table, @Param("date") String date);

        /**
         * 插入全网报块数
         * @param tableName
         * @param height
         * @return
         */
        public boolean insertNetBlock(@Param("tableName") String tableName, @Param("height") Long height);

        /**
         * 查询全网的报块数
         * @param tableName
         * @return
         */
        public List<BlockInfoDto> selectNetBlock(@Param("tableName") String tableName);


        /**
         * 查询矿池的有效宝库阿叔
         * @param reduce 多少天以前
         * @return
         */
        @DistributionDB
        public int selectPoolBlock(@Param("start")Date start,@Param("end")Date end,@Param("coin")String coin,@Param("reduce")int reduce);

        /**
         * 查询一段时间内矿池平均算力
         * @param coin
         * @param start
         * @param end
         * @return
         */
        DateBigDecimalDto getAvgPowerForPool(@Param("coin") String coin, @Param("start")Date start, @Param("end")Date end);

        /**
         * 查询一段时间段内全网平均算力
         * @param coin
         * @param start
         * @param end
         * @return
         */
        DateBigDecimalDto getAvgPowerForNet(@Param("coin") String coin, @Param("start")Date start, @Param("end")Date end);


        /**
         *
         * @param coin
         * @param startTime
         * @return
         */
        @HashRateDB
        List<MinerMhsDto> getMinerPowerFor30min(@Param("coin") String coin, @Param("startTime") LocalDateTime startTime,@Param("endTime") LocalDateTime endTime);


        /**
         * 查询dgb系列各币种对应的全网报块信息
         * @param tableName
         * @return
         */
        BlockInfoDto getDgbSeriesBlock(@Param("tableName") String tableName);

        /**
         * 获取dgb 系列币总的最新高度
         * @return
         */
        Integer getDgbTotalHeight();


        /**
         * 向dgb表中，插入最新新的高度
         * @param height
         * @return
         */
        Integer insertDgbTotalHeight(@Param("height") Long height);


        /**
         * 获取门罗币报块信息信息
         * @param coin
         * @return
         */
        BlockInfo getMoneroBlockInfo();

        BlockInfo getXtmBlockInfo();

        int insertXtmBlockInfo(@Param("blockInfo") BlockInfo blockInfo);


        int deleteMhs30m(@Param("coin") String coin,@Param("date") String date);

        int deletePool30m(@Param("coin") String coin,@Param("date") String date);

        int deleteUsers30m(@Param("coin") String coin,@Param("date") String date);


        List<NoticeMinerCoinListDto> getEmailByUsers(@Param("list")  List<OfflineUserMinerDto> list,@Param("coin")String coin );

}
