package com.m2pool.pool.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.m2pool.common.core.utils.DateUtils;
import com.m2pool.common.core.utils.StringUtils;
import com.m2pool.common.core.web.Result.AjaxResult;
import com.m2pool.pool.enums.NodeConstant;
import com.m2pool.system.api.RemoteUserService;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


/**
 * @Description TODO
 * @Date 2024/6/24 10:21
 * @Author 杜懿
 */
public class Test {



    private static String COINMARKETCAP_KEY="ba4fc555-e8b3-4bb2-aa91-bfa81044e8bf";
    public static String PWD_REGEX="^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[!@#$%^&*)(_+}{|:?><]).{8,32}$";
    public static void main(String[] args) {
//30d 数据只有6d  6天算出来是12%  剩下24天设置未为100%
//        String nowStr = DateUtils.dateTimeNow(DateUtils.YYYY_MM_DD);
//        System.out.println(nowStr);
        //Date now = DateUtils.parseDate( nowStr);
        //System.out.println(now);
        //List<BlockInfoDto> tbList = new ArrayList<>();
        //
        //BigDecimal a1 = BigDecimal.valueOf(25);
        //BigDecimal b2 = BigDecimal.valueOf(4);
        //BigDecimal bigDecimal = a1.divide(b2).setScale(10, BigDecimal.ROUND_HALF_UP);
        //System.out.println(BigDecimal.valueOf(6.72).setScale(10,BigDecimal.ROUND_HALF_UP));
        //
        //
        ////今日矿池总收益
        ////BigDecimal reward = tbList.stream()
        ////        .filter(e -> (e.getDate().before(now) || e.getDate().equals(now)))
        ////        .map(e -> {
        ////            return BigDecimal.valueOf(e.getReward());
        ////        }).reduce(BigDecimal.ZERO, BigDecimal::add);
        ////今日总收益 * 用户今日平均算力占比 = 用户今日预估收益
        ////System.out.println(reward);
        //BigDecimal diff = new BigDecimal(247809.339528107);
        BigDecimal diff = BigDecimal.valueOf(
                273308829306273.9).multiply(BigDecimal.valueOf(10));

        System.out.println(diff);

        BigDecimal vip = BigDecimal.valueOf(
                4866660414177.179);

        //27764650.22400000 *

        NodeConstant constant = NodeConstant.ALPH;

        BigDecimal factor =  constant.getFactor();
        System.out.println("factor:"+factor);

        BigDecimal my = diff.multiply(factor).setScale(3,BigDecimal.ROUND_HALF_UP);
        String s = PowerUnitUtils.difficultyFormat(diff);
        ///134.654.677 84243162
        System.out.println(s);
        System.out.println(my);

        //BigDecimal out = null;
        //System.out.println("收"+BigDecimal.valueOf(285).add(out).setScale(2,BigDecimal.ROUND_HALF_UP));
        //String dgbs = PowerUnitUtils.powerFormat(my, "dgbs");
        //System.out.println(dgbs);
        //
        //BigDecimal divide1 = BigDecimal.valueOf(167810)
        //        .multiply(factor)
        //        .divide(BigDecimal.valueOf(1000000000), 16, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(1.02));
        //
        ////1T = 1000G = 1000*1000M =1000*1000*1000K = 1000*1000*1000*1000 H/s
        //BigDecimal hashrate = BigDecimal.valueOf(6552.87).multiply(BigDecimal.valueOf(1000)).multiply(BigDecimal.valueOf(1000*1000));
        //System.out.println("算力："+hashrate+",逆推难度："+hashrate.divide(factor,16,BigDecimal.ROUND_HALF_UP));
        //
        //
        //BigDecimal hashrate2 = BigDecimal.valueOf(6.56287).multiply(BigDecimal.valueOf(1000*1000)).multiply(BigDecimal.valueOf(1000*1000));
        //System.out.println("算力："+hashrate2+",逆推难度："+hashrate2.divide(factor,16,BigDecimal.ROUND_HALF_UP));
        //String ip=null;
        //if(StringUtils.isNull(ip)){
        //    ip="";
        //}
        //
        //BigDecimal a= BigDecimal.valueOf(34988050.7409206319)
        //        .multiply(BigDecimal.valueOf(1000*1000));
        //BigDecimal b= BigDecimal.valueOf(40358179185625.603034);
        //System.out.println(a);
        //System.out.println(a.divide(b,16,BigDecimal.ROUND_HALF_UP));
        //System.out.println(a.divide(b,16,BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(960*3)));
        //
        //
        //long pDay3d = 3;
        //
        ////矿池单位转换
        //BigDecimal pPow3d = BigDecimal.valueOf(35032458.5686897500)
        //        .add(BigDecimal.valueOf(34978857.3181887708))
        //        .add(BigDecimal.valueOf(34952836.3358833750))
        //        .multiply(BigDecimal.valueOf(1000*1000));
        //
        //long nDay3d = 3;
        //
        //BigDecimal nPow3d = BigDecimal.valueOf(37823319087186.226875)
        //        .add(BigDecimal.valueOf(42368092071445.108958))
        //        .add(BigDecimal.valueOf(40921609879113.265238));
        ////计算3天 每日出块量
        //BigDecimal dayChunk3d = pPow3d
        //        .multiply(BigDecimal.valueOf(nDay3d * nDay3d))
        //        .divide(nPow3d.multiply(BigDecimal.valueOf(pDay3d * pDay3d)),8,BigDecimal.ROUND_HALF_UP)
        //        .multiply(BigDecimal.valueOf(960))
        //        .setScale(8, BigDecimal.ROUND_HALF_UP);
        //System.out.println("3天每日应出块量："+dayChunk3d);
        //System.out.println(BigDecimal.valueOf(2731).divide(dayChunk3d.multiply(BigDecimal.valueOf(3)),4,BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)).doubleValue());

        //String heightBody ="{\"headers\": [\"000000000000065796e173ae9c9f8ec1bae6c95083894444866a50bd2e61fac0\",\"000000000000065796e173ae9c9f8ec1bae6c95083894444866a50bd2e6test1\",\"000000000000065796e173ae9c9f8ec1bae6c95083894444866a50bd2e6test2\"]}";
        String hashRateBody ="{\"hashrate\": \"32071693244 MH/s\"}";
        JSONObject hashRateJsonObject = JSON.parseObject(hashRateBody);
        System.out.println("alph 当前算力api请求结果：|"+hashRateJsonObject+"|");
        String hashRateStr = hashRateJsonObject.getString("hashrate");
        String hashRateError = hashRateJsonObject.getString("detail");

        if (StringUtils.isNull(hashRateStr) && StringUtils.isNotBlank(hashRateError)){
            System.out.println("当前全网算力APi调用 error:"+hashRateError);
        }
        if(StringUtils.isNull(hashRateStr) && StringUtils.isBlank(hashRateError)){
            System.out.println("当前全网算力APi调用 未通过hashes获取到数据");
        }
        BigDecimal hashrate= BigDecimal.ONE;
        if(hashRateStr.toUpperCase().contains("kh/s")){
            hashrate = new BigDecimal(hashRateStr.
                    replace("KH/s","").
                    replace(" ","")).
                    multiply(BigDecimal.valueOf(1000,2));
        }else if(hashRateStr.toLowerCase().contains("mh/s")){
            System.out.println("mh");
            hashrate = new BigDecimal(hashRateStr.
                    replace("MH/s","").
                    replace(" ","")).
                    multiply(BigDecimal.valueOf(1000*1000));


        }else if(hashRateStr.toLowerCase().contains("gh/s")){
            hashrate = new BigDecimal(hashRateStr.
                    replace("GH/s","").
                    replace(" ","")).
                    multiply(BigDecimal.valueOf(1000*1000,2)).
                    multiply(BigDecimal.valueOf(1000,2));
        }else if(hashRateStr.toLowerCase().contains("th/s")){
            hashrate = new BigDecimal(hashRateStr.
                    replace("TH/s","").
                    replace(" ","")).
                    multiply(BigDecimal.valueOf(1000*1000,2)).
                    multiply(BigDecimal.valueOf(1000*1000,2));
        }else if(hashRateStr.toLowerCase().contains("ph/s")){
            hashrate = new BigDecimal(hashRateStr.
                    replace("PH/s","").
                    replace(" ","")).
                    multiply(BigDecimal.valueOf(1000*1000,2)).
                    multiply(BigDecimal.valueOf(1000*1000,2)).
                    multiply(BigDecimal.valueOf(1000,2));
        }else if(hashRateStr.toLowerCase().contains("h/s")){
            hashrate = new BigDecimal(hashRateStr.
                    replace("H/s","").
                    replace(" ",""));
        }else {
            //
        }

        System.out.println(hashrate);


    }

}

