package com.mcwl.web.controller.resource;

import com.mcwl.common.core.domain.R;
import com.mcwl.resource.domain.dto.SysAdviceDto;
import com.mcwl.resource.domain.vo.AdviceVo;
import com.mcwl.resource.domain.vo.AttentionAdviceVo;
import com.mcwl.resource.domain.vo.CommentAdviceVo;
import com.mcwl.resource.domain.vo.LikeAdviceVo;
import com.mcwl.resource.service.ISysAdviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 消息通知
 */
@RestController
@RequestMapping("advice")
@RequiredArgsConstructor
@Api(tags = "消息通知")
public class SysAdviceController {

    private final ISysAdviceService sysAdviceService;

    /**
     * 发送系统消息
     *
     @NotNull(message = "消息内容不能为空")
     @ApiParam(value = "消息内容", required = true)
     String adviceContent
     */
//    @PreAuthorize("@ss.hasPermi('system:advice:add')")
    @PostMapping("sendSysMsg")
    @ApiOperation(value = "添加系统消息")
    public R<String> sendSysMsg(@Valid @RequestBody SysAdviceDto sysAdviceDto) {
        sysAdviceService.sendSysMsg(sysAdviceDto);
        return R.ok();
    }


    /**
     * 已读
     */
    @GetMapping("read")
    @ApiOperation(value = "已读")
    public R<String> read(@Valid
                          @NotNull(message = "消息id不能为空")
                          @ApiParam(value = "消息id", required = true)
                          Long adviceId) {
        sysAdviceService.read(adviceId);
        return R.ok();
    }

    /**
     * 一键已读
     */
    @GetMapping("readAll")
    @ApiOperation(value = "一键已读")
    public R<String> readAll() {
        sysAdviceService.readAll();
        return R.ok();
    }


    /**
     * 获取所有通知
     */
    @GetMapping("getAllMsg")
    @ApiOperation(value = "获取所有通知")
    public R<List<AdviceVo>> getAllMsg() {
        List<AdviceVo> adviceVo = sysAdviceService.getAllMsg();
        return R.ok(adviceVo);
    }

    /**
     * 获取官方通知
     */
    @GetMapping("getOfficialMsg")
    @ApiOperation(value = "获取官方通知")
    public R<List<AdviceVo>> getOfficialMsg() {
        List<AdviceVo> adviceVo = sysAdviceService.getOfficialMsg();
        return R.ok(adviceVo);
    }


    /**
     * 获取评论通知
     */
    @GetMapping("getCommentMsg")
    @ApiOperation(value = "获取评论通知")
    public R<List<CommentAdviceVo>> getCommentMsg(@Valid
                                                  @NotNull(message = "类型不能为空")
                                                  @ApiParam(value = "类型 0模型 1工作流 2图片 3全部", required = true)
                                                  Integer productType) {
        List<CommentAdviceVo> adviceVo = sysAdviceService.getCommentMsg(productType);
        return R.ok(adviceVo);
    }

    /**
     * 获取点赞通知
     */
    @GetMapping("getLikeMsg")
    @ApiOperation(value = "获取点赞通知")
    public R<List<LikeAdviceVo>> getLikeMsg(@Valid
                                            @NotNull(message = "类型不能为空")
                                            @ApiParam(value = "类型 0模型 1工作流 2图片 3评论 4全部", required = true)
                                            Integer productType) {
        List<LikeAdviceVo> likeAdviceVoList = sysAdviceService.getLikeMsg(productType);
        return R.ok(likeAdviceVoList);
    }


    /**
     * 获取关注通知
     */
    @GetMapping("getAttentionMsg")
    @ApiOperation(value = "获取关注通知")
    public R<List<AttentionAdviceVo>> getAttentionMsg() {
        List<AttentionAdviceVo> attentionAdviceVoList = sysAdviceService.getAttentionMsg();
        return R.ok(attentionAdviceVoList);
    }

}
