package com.m2pool.pool.controller;

import com.github.pagehelper.PageHelper;
import com.m2pool.common.core.utils.StringUtils;
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.UserReadPageInfoReturnDto;
import com.m2pool.pool.service.ReadOnlyService;
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("/read")
public class ReadOnlyController extends BaseController {

    @Autowired
    private ReadOnlyService roService;

    @PostMapping("/getHtmlUrl")
    @ApiOperation(value = "创建只读页面 ")
    @RequiresLogin
    public AjaxResult getHtmlUrl(@Valid @RequestBody ReadOnlyHtmlCreateVo vo){

        return  roService.createPageUrl(vo);

    }

    @PostMapping("/getUrlList")
    @ApiOperation(value = "获取当前用户只读页面列表 ")
    @RequiresLogin
    public TableDataInfo getUrlList(@RequestBody(required = false) PageVo vo){

        if(StringUtils.isNull(vo)){
            vo = new PageVo();
        }
        PageHelper.clearPage();
        return  roService.getUrlList(vo);

    }


    @PostMapping("/getUrlInfo")
    @ApiOperation(value = "获取当前只读页面基础信息 ")
    @RequiresLogin
    public AjaxResult getUrlInfo(@Valid @RequestBody ReadOnlyKeyVo vo){
        return  roService.getUrlInfo(vo);

    }

    @PostMapping("/changeUrlInfo")
    @ApiOperation(value = "修改只读页面 只能修改备注和权限")
    @RequiresLogin
    public AjaxResult changeUrlInfo(@Valid @RequestBody ReadOnlyHtmlChangeVo vo){

        return  roService.changeUrlInfo(vo);

    }

    @DeleteMapping("/delPage")
    @ApiOperation(value = "删除只读页面")
    @RequiresLogin
    public AjaxResult delPage(@Valid @RequestBody ReadOnlyKeyVo vo){

        return  roService.delPageByKey(vo);

    }


    @PostMapping("/getPageInfo")
    @ApiOperation(value = "只读页面 获取只读页面 权限信息")
    public AjaxResult getPageInfo(@Valid @RequestBody ReadOnlyKeyVo vo){

        return  roService.getPageInfo(vo);

    }

    @PostMapping("/getMinerAccountPower")
    @ApiOperation(value = "只读页面 获取只读页面 挖矿账号算力曲线图")
    public AjaxResult getMinerAccountPower(@Valid @RequestBody ReadOnlyIntervalVo vo){

        return  roService.getMinerAccountPower(vo);

    }

    @PostMapping("/getAccountPowerDistribution")
    @ApiOperation(value = "只读页面 获取挖矿账号算力分布 柱状图")
    public AjaxResult getAccountPowerDistribution(@Valid @RequestBody ReadOnlyIntervalVo vo){

        return  roService.getAccountPowerDistribution(vo);

    }

    @PostMapping("/getProfitInfo")
    @ApiOperation(value = "只读页面 获取挖矿账户收益信息")
    public AjaxResult getMinerAccountInfo(@Valid @RequestBody ReadOnlyKeyVo vo){

        return  roService.getProfitInfo(vo);

    }

    @PostMapping("/getMinerList")
    @ApiOperation(value = "只读页面 获取挖矿账户下矿工详情")
    public AjaxResult getMinerList(@Valid @RequestBody ReadOnlyListVo vo){
        PageHelper.clearPage();
        return  roService.getMinerList(vo);

    }

    @PostMapping("/getMinerPower")
    @ApiOperation(value = "只读页面 获取矿工算力曲线图")
    public AjaxResult getMinerPower(@Valid @RequestBody ReadOnlyMinerVo vo){

        return  roService.getMinerPower(vo);

    }


    @PostMapping("/getHistoryIncome")
    @ApiOperation(value = "获取收益历史记录")
    public TableDataInfo getHistoryIncome(@RequestBody() ReadOnlyPageVo vo){
        PageHelper.clearPage();
        return  roService.getHistoryIncome(vo);
    }

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

        PageHelper.clearPage();
        return  roService.getHistoryOutcome(vo);
    }


}
