package com.m2pool.pool.controller;

import com.github.pagehelper.PageHelper;
import com.m2pool.common.core.web.Result.AjaxResult;
import com.m2pool.common.core.web.controller.BaseController;
import com.m2pool.common.core.web.page.TableDataInfo;
import com.m2pool.common.security.annotation.RequiresLogin;
import com.m2pool.pool.dto.BlockInfoDto;
import com.m2pool.pool.service.MinerAccountService;
import com.m2pool.pool.service.PoolService;
import com.m2pool.pool.vo.*;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @Description 统一请求接口
 * @Date 2024/6/14 9:54
 * @Author dy
 */
@RestController
//@RequestMapping("/pool")
public class PoolController extends BaseController {

    @Autowired
    private PoolService poolService;

    @Autowired
    private MinerAccountService maService;


    @PostMapping("/getCoinInfo")
    @ApiOperation(value = "获取币种(矿池)信息")
    public AjaxResult getCoinInfo(@Valid @RequestBody CoinVo vo){

        return  poolService.getPoolInfo(vo);

    }

    @PostMapping("/checkAccount")
    @ApiOperation(value = "校验挖矿账号是否存在")
    public boolean checkAccount(@Valid @RequestBody MinerAccountAddVo vo){

        return  poolService.checkAccount(vo);

    }

    @PostMapping("/getPoolPower")
    @ApiOperation(value = "获取币种(矿池)算力曲线图")
    public AjaxResult getPoolPower(@Valid @RequestBody CoinVo vo){

        return  poolService.getPoolPower(vo);

    }

    //@PostMapping("/getMinerCount")
    //@ApiOperation(value = "获取币种(矿池)矿工数量曲线图")
    //public AjaxResult getMinerCount(@Valid @RequestBody CoinVo com.m2pool.chat.vo){
    //
    //    return  poolService.getMinerCount(com.m2pool.chat.vo);
    //
    //}

    @PostMapping("/getLuck")
    @ApiOperation(value = "获取币种(矿池)幸运值")
    public AjaxResult getLuck(@Valid @RequestBody CoinVo vo){

        return  poolService.getLuckByCoin(vo);

    }

    @PostMapping("/getBlockInfo")
    @ApiOperation(value = "获取币种(矿池)报块信息")
    public TableDataInfo getBlockInfo(@RequestBody() CoinVo vo){
        PageHelper.startPage(vo.getPage(),vo.getLimit());
        List<BlockInfoDto> list = poolService.getBlockInfoList(vo);
        return  getDataTable(list);
    }

    //@PostMapping("/getPoolPowerDistribution")
    //@ApiOperation(value = "获取当前矿池算力分布 柱状图")
    //public AjaxResult getPoolPowerDistribution(@Valid @RequestBody CoinVo com.m2pool.chat.vo){
    //    //暂未使用
    //    return  poolService.getPoolPowerDistribution(com.m2pool.chat.vo);
    //
    //}

    @PostMapping("/getMinerAccountPower")
    @ApiOperation(value = "获取当前挖矿账号算力曲线图")
    @RequiresLogin
    public AjaxResult getMinerAccountPower(@Valid @RequestBody AccountVo vo){

        return  maService.getMinerAccountPower(vo);

    }

    @PostMapping("/getAccountPowerDistribution")
    @ApiOperation(value = "获取当前挖矿账号算力分布 柱状图")
    @RequiresLogin
    public AjaxResult getAccountPowerDistribution(@Valid @RequestBody AccountVo vo){

        return  maService.getAccountPowerDistribution(vo);

    }

    @PostMapping("/getMinerAccountInfo")
    @ApiOperation(value = "获取当前挖矿账户收益信息")
    @RequiresLogin
    public AjaxResult getMinerAccountInfo(@Valid @RequestBody AccountVo vo){

        return  maService.getMinerAccountInfo(vo);

    }

    @PostMapping("/getMinerList")
    @ApiOperation(value = "获取当前挖矿账户下矿工详情")
    @RequiresLogin
    public AjaxResult getMinerList(@Valid @RequestBody MinerListVo vo){

        return  maService.getMinerList(vo);

    }

    @PostMapping("/getMinerPower")
    @ApiOperation(value = "获取矿工算力曲线图")
    @RequiresLogin
    public AjaxResult getMinerPower(@Valid @RequestBody MinerVo vo){

        return  maService.getMinerPower(vo);

    }

    //@PostMapping("/getMinerPowerDistribution")
    //@ApiOperation(value = "获取矿工算力分布 柱状图")
    //@RequiresLogin
    //public AjaxResult getMinerPowerDistribution(@Valid @RequestBody MinerVo com.m2pool.chat.vo){
    //
    //    return  maService.getMinerPowerDistribution(com.m2pool.chat.vo);
    //
    //}

    @PostMapping("/getHistoryIncome")
    @ApiOperation(value = "获取收益历史记录")
    @RequiresLogin
    public TableDataInfo getHistoryIncome(@RequestBody() AccountVo vo){

        //PageHelper.startPage(com.m2pool.chat.vo.getPage(),com.m2pool.chat.vo.getLimit());
        return  maService.getHistoryIncome(vo);
    }

    @PostMapping("/getHistoryOutcome")
    @ApiOperation(value = "获取账号提现历史记录")
    @RequiresLogin
    public TableDataInfo getHistoryOutcome(@RequestBody() AccountVo vo){

        return  maService.getHistoryOutcome(vo);
    }

    @PostMapping(value = {"/getCoinBalanceList","/getCoinBalancetList"})
    @ApiOperation(value = "获取币种余额list")
    public AjaxResult getCoinBalancetList(@RequestBody BalanceListGetVo vo){

        return  poolService.getCoinBalanceList(vo);

    }

    @PostMapping("/getNetPower")
    @ApiOperation(value = "获取全网算力曲线")
    public AjaxResult getNetPower(@Valid @RequestBody CoinVo vo){

        return  poolService.getNetPower(vo);

    }

    @PostMapping("/getParam")
    @ApiOperation(value = "根据币种获取计算器相关参数")
    public AjaxResult getParam(@Valid @RequestBody CoinVo vo){

        return  poolService.getParam(vo);

    }

    @PostMapping("/getMinerPowerFor30min")
    @ApiOperation(value = "根据矿工账号从hashrate库获取算力")
    public AjaxResult getMinerPowerFor30min(@RequestBody MinerMhsVo minerMhsVo){
        return poolService.getMinerPowerFor30min(minerMhsVo);
    }


    @GetMapping("/test2")
    @ApiOperation(value = "")
    public AjaxResult test2(){

        return  poolService.test2();
    }


    @GetMapping("/test1")
    @ApiOperation(value = "")
    public AjaxResult test1(){

        return  poolService.test1();
    }

    @PostMapping("/dataSupplement")
    public String dataSupplement(@RequestBody DataSupplementVo vo){
        if (vo.getKey().equals("dsadasdwfddasdfsafadsfs")){
            return poolService.dataSupplement(vo);
        }else{
            return "失败:key传递错误";
        }
    }

    @PostMapping("/dataDelete")
    public String dataDelete(@RequestBody DataSupplementVo vo){
        if (vo.getKey().equals("dsadasdwfddasdfsafadsfs")){
            return poolService.dataDelete(vo);
        }else{
            return "失败:key传递错误";
        }
    }


}
