package com.m2pool.oapi.controller;

import com.m2pool.common.core.annotation.RateLimiter;
import com.m2pool.common.core.enums.LimitType;
import com.m2pool.common.core.web.Result.AjaxResult;
import com.m2pool.common.core.web.controller.BaseController;
import com.m2pool.common.security.annotation.OpenApiPermissions;
import com.m2pool.common.security.annotation.RequiresPermissions;
import com.m2pool.oapi.service.PoolService;
import com.m2pool.oapi.vo.CoinVo;
import com.m2pool.oapi.vo.DateVo;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

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

    @Autowired
    private PoolService poolService;

    @GetMapping("/hashrate")
    @ApiOperation(value = "矿池实时算力")
    @OpenApiPermissions("pool")
    public AjaxResult hashrate(@Valid CoinVo vo){

        return  poolService.getHashRate(vo);

    }

    @GetMapping("/hashrate_history")
    @ApiOperation(value = "矿池历史算力(最多3个月)")
    @OpenApiPermissions("pool")
    public AjaxResult hashRateHistory(@Valid DateVo vo){

        return  poolService.getHashRateHistory(vo);

    }

    @GetMapping("/miners_list")
    @ApiOperation(value = "矿池当前矿工数")
    @OpenApiPermissions("pool")
    public AjaxResult getMinersList(@Valid CoinVo vo){

        return  poolService.getMinersList(vo);

    }

    @GetMapping("/watch")
    @ApiOperation(value = "矿池总览")
    @OpenApiPermissions("pool")
    @RateLimiter(time = 1,count = 5,limitType = LimitType.IP)
    public AjaxResult watch(@Valid CoinVo vo){

        return  poolService.getWatch(vo);

    }

    @PostMapping("/test")
    @ApiOperation(value = "矿池总览")
    @OpenApiPermissions("pool")
    public AjaxResult test(@Valid @RequestBody CoinVo vo){

        return  AjaxResult.success();

    }


}
