package com.m2pool.manage.controller;

import com.m2pool.common.core.Result.R;
import com.m2pool.common.core.utils.PageUtils;
import com.m2pool.common.core.web.page.TableDataInfo;
import com.m2pool.common.security.annotation.Logical;
import com.m2pool.common.security.annotation.RequiresLogin;
import com.m2pool.common.security.annotation.RequiresRoles;
import com.m2pool.manage.dto.ManageBroadcastDto;
import com.m2pool.manage.service.ManageBroadcastService;
import com.m2pool.manage.vo.ManageBaseVo;
import com.m2pool.manage.vo.ManageBroadcastVo;
import com.m2pool.manage.vo.PageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * @Description 广播信息控制器类
 * @Date 2025/5/22 14:22
 * @Author yyb
 */
@RestController
@RequestMapping("/broadcast")
@Api(tags = "广播信息控制器类")
public class ManageBroadcastController {

    @Resource
    private ManageBroadcastService manageBroadcastService;

    @PostMapping("/get/list/by/page")
    @ApiOperation(value = "管理系统:分页查询所有广播信息")
    @RequiresLogin
    @RequiresRoles(value = {"back_admin","admin"}, logical = Logical.OR)
    public TableDataInfo<ManageBroadcastDto> getListDataByPage(@RequestBody PageVo pageVo){
        return manageBroadcastService.getListDataByPage(pageVo);
    }

    @PostMapping("/find/data/by/id")
    @ApiOperation(value = "业务系统:用于获取m2pool广播数据")
    public R<List<ManageBroadcastDto>> findDataById(@RequestBody(required = false) ManageBaseVo manageBaseVo){
        return manageBroadcastService.findDataById(manageBaseVo);
    }

    @PostMapping("/add")
    @ApiOperation(value = "管理系统:新增广播")
    @RequiresLogin
    @RequiresRoles(value = {"back_admin","admin"}, logical = Logical.OR)
    public R<String> add(@RequestBody ManageBroadcastVo broadcastVo){
        return manageBroadcastService.addBroadcast(broadcastVo);
    }

    @PostMapping("/delete")
    @ApiOperation(value = "管理系统:删除广播")
    @RequiresLogin
    @RequiresRoles(value = {"back_admin","admin"}, logical = Logical.OR)
    public R<String> delete(@RequestBody ManageBaseVo manageBaseVo){
        return manageBroadcastService.deleteBroadcastById(manageBaseVo.getId());
    }

    @PostMapping("/update")
    @ApiOperation(value = "管理系统:修改广播")
    @RequiresLogin
    @RequiresRoles(value = {"back_admin","admin"}, logical = Logical.OR)
    public R<String> update(@RequestBody ManageBroadcastVo broadcastVo){
        return manageBroadcastService.updateBroadcast(broadcastVo);
    }

    @PostMapping("/find/data/info")
    @ApiOperation(value = "管理系统:用于获取通知详情")
    @RequiresRoles(value = {"back_admin","admin"}, logical = Logical.OR)
    public R<ManageBroadcastDto> findDataInfo(@RequestBody ManageBaseVo manageBaseVo){
        return manageBroadcastService.findDataInfo(manageBaseVo);
    }


}
