package com.ningdatech.pmapi.sys.controller;

import com.ningdatech.basic.model.IdVo;
import com.ningdatech.basic.model.PageVo;
import com.ningdatech.log.annotation.WebLog;
import com.ningdatech.pmapi.sys.manage.NoticeManage;
import com.ningdatech.pmapi.sys.model.req.NoticeListReq;
import com.ningdatech.pmapi.sys.model.req.NoticeSaveReq;
import com.ningdatech.pmapi.sys.model.req.NoticeStatusModifyReq;
import com.ningdatech.pmapi.sys.model.vo.NoticeDetailVO;
import com.ningdatech.pmapi.sys.model.vo.NoticeListItemVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 系统公告 前端控制器
 * </p>
 *
 * @author WendyYang
 * @since 2022-07-21
 */
@RestController
@Api(tags = "公告管理")
@RequiredArgsConstructor
@RequestMapping("/api/v1/notice")
public class NoticeController {

    private final NoticeManage noticeManage;

    @PostMapping("/save")
    @ApiOperation("新增公告")
    @WebLog("新增公告")
    public IdVo<Long> save(@Valid @RequestBody NoticeSaveReq req) {
        return noticeManage.saveOrModify(req);
    }

    @GetMapping("/detail/{id}")
    @ApiOperation("公告详情")
    public NoticeDetailVO save(@PathVariable Long id) {
        return noticeManage.detail(id);
    }

    @PostMapping("/enabled")
    @ApiOperation("启用/禁用")
    @WebLog("启用/禁用")
    public Boolean save(@Valid @RequestBody NoticeStatusModifyReq req) {
        return noticeManage.changeEnabled(req);
    }

    @PostMapping("/topped")
    @ApiOperation("置顶")
    @WebLog("置顶")
    public void topped(@RequestBody IdVo<Long> id) {
        noticeManage.topped(id.getId());
    }

    @GetMapping("/dashboard/list")
    @ApiOperation("工作台公告列表")
    public PageVo<NoticeListItemVO> dashboardList(@RequestParam(required = false, defaultValue = "3") Integer limit,
                                                  @RequestParam(required = false) Integer type) {
        return noticeManage.dashboardList(limit, type);
    }

    @GetMapping("/manage/list")
    @ApiOperation("公告管理列表")
    public PageVo<NoticeListItemVO> listByManager(NoticeListReq req) {
        return noticeManage.listByManager(req);
    }

    @DeleteMapping("/del")
    @ApiOperation("删除公告")
    @WebLog("删除公告")
    public void delNotice(@RequestBody IdVo<Long> req) {
        noticeManage.delNotice(req.getId());
    }

}
