package ink.wgink.module.instantmessage.controller.api;

import ink.wgink.annotation.CheckRequestBodyAnnotation;
import ink.wgink.common.base.DefaultBaseController;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.module.instantmessage.pojo.dtos.NoticeDTO;
import ink.wgink.module.instantmessage.pojo.vos.NoticeSendVO;
import ink.wgink.module.instantmessage.service.INoticeService;
import ink.wgink.pojo.ListPage;
import ink.wgink.pojo.result.ErrorResult;
import ink.wgink.pojo.result.SuccessResult;
import ink.wgink.pojo.result.SuccessResultList;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * When you feel like quitting. Think about why you started
 * 当你想要放弃的时候，想想当初你为何开始
 *
 * @ClassName: MessageController
 * @Description: 消息
 * @Author: wanggeng
 * @Date: 2021/1/14 3:25 下午
 * @Version: 1.0
 */
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "消息接口")
@RestController
@RequestMapping(ISystemConstant.API_PREFIX + "/websocket/notice")
public class WebSocketNoticeController extends DefaultBaseController {

    @Autowired
    private INoticeService noticeService;

    @ApiOperation(value = "删除通知", notes = "删除通知接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "noticeIds", value = "通知ID列表", paramType = "path"),
    })
    @DeleteMapping("remove/{noticeIds}")
    public SuccessResult delete(@PathVariable("noticeIds") String noticeIds) {
        noticeService.remove(Arrays.asList(noticeIds.split("\\_")));
        return new SuccessResult();
    }

    @ApiOperation(value = "通知列表", notes = "通知列表接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("list")
    public List<NoticeDTO> list() {
        Map<String, Object> params = requestParams();
        return noticeService.list(params);
    }

    @ApiOperation(value = "通知分页列表", notes = "通知分页列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"),
            @ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "String")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("listpage")
    public SuccessResultList<List<NoticeDTO>> listPage(ListPage page) {
        Map<String, Object> params = requestParams();
        page.setParams(params);
        return noticeService.listPage(page);
    }

}
