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.NoticeListDto;
import com.m2pool.pool.service.NoticeService;
import com.m2pool.pool.vo.NoticeAddVo;
import com.m2pool.pool.vo.NoticeDelVo;
import com.m2pool.pool.vo.NoticePageVo;
import com.m2pool.pool.vo.NoticeUpdateVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description 告警系统相关请求接口
 * @Date 2024/6/14 9:54
 * @Author dy
 */
@RestController
@RequestMapping("/notice")
public class NoticeController extends BaseController {

    @Resource
    private NoticeService noticeService;


    @PostMapping("/addNoticeEmail")
    @ApiOperation(value = "添加告警邮箱")
    @RequiresLogin
    public AjaxResult addNoticeEmail(@RequestBody NoticeAddVo vo){

        return  noticeService.addNoticeEmail(vo);

    }

    @PostMapping("/getCode")
    @ApiOperation(value = "绑定通知邮箱 发送邮箱验证码")
    @RequiresLogin
    public AjaxResult getCode(@RequestBody NoticeAddVo vo){
        clearPage();
        return  noticeService.getCode(vo);

    }

    @PostMapping("/getList")
    @ApiOperation(value = "获取当前用户绑定的通知邮箱列表 ")
    @RequiresLogin
    public TableDataInfo getNoticeEmailList(@RequestBody NoticePageVo vo){

        PageHelper.startPage(vo.getPage(),vo.getLimit());
        List<NoticeListDto> list = noticeService.getNoticeEmailList(vo);
        return  getDataTable(list);

    }

    @PostMapping("/updateInfo")
    @ApiOperation(value = "修改通知邮箱备注信息")
    @RequiresLogin
    public AjaxResult updateInfo(@RequestBody NoticeUpdateVo vo){

        return  noticeService.updateInfo(vo);

    }

    @DeleteMapping("/deleteEmail")
    @ApiOperation(value = "删除通知邮箱")
    @RequiresLogin
    public AjaxResult deleteEmail(@RequestBody NoticeDelVo vo){

        return  noticeService.deleteEmail(vo);

    }

    //@PostMapping("/getNoticeInfoListInCache")
    //@ApiOperation(value = "获取用户最新的矿机在离线警报")
    //@RequiresLogin
    //public AjaxResult getNoticeInfoListInCache(){
    //    return  noticeService.getNoticeInfoListInCache();
    //}



}
