package com.red.circle.console.adapter.app.sys;


import com.red.circle.console.app.service.app.sys.SysNoticeMessageService;
import com.red.circle.console.infra.annotations.OpsOperationReqLog;
import com.red.circle.framework.dto.PageResult;
import com.red.circle.framework.web.controller.BaseController;
import com.red.circle.other.inner.model.cmd.sys.SysNoticeMessageCmd;
import com.red.circle.other.inner.model.cmd.sys.SysNoticeMessageQryCmd;
import com.red.circle.other.inner.model.dto.sys.SysNoticeMessageDTO;
import com.red.circle.tool.core.date.TimestampUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 系统公告通知消息 前端控制器.
 * </p>
 *
 * @author houyong
 * @since 2021-04-02
 */
@RestController
@RequestMapping("/sys/notice/message")
@RequiredArgsConstructor
public class SysNoticeMessageRestController extends BaseController {

  private final SysNoticeMessageService sysNoticeMessageService;

  /**
   * 获取系统公告通知消息.
   */
  @GetMapping
  public PageResult<SysNoticeMessageDTO> getNoticeMessage(SysNoticeMessageQryCmd query) {
    return sysNoticeMessageService.getNoticeMessage(query);
  }

  @OpsOperationReqLog("添加系统公告通知消息")
  @PostMapping
  public void addNoticeMessage(@RequestBody SysNoticeMessageCmd sysNoticeMessage) {
    sysNoticeMessageService.addNoticeMessage(sysNoticeMessage);
  }

  @OpsOperationReqLog("删除系统公告通知消息")
  @DeleteMapping("/{id}")
  public void deleteNoticeMessage(@PathVariable("id") Long id) {
    sysNoticeMessageService.deleteNoticeMessage(id);
  }

  @OpsOperationReqLog("修改系统公告通知消息")
  @PutMapping
  public void updateNoticeMessage(@RequestBody SysNoticeMessageCmd sysNoticeMessage) {
    sysNoticeMessage.setUpdateUser(sysNoticeMessage.getReqUserId());
    sysNoticeMessage.setUpdateTime(TimestampUtils.now());
    sysNoticeMessageService.updateNoticeMessage(sysNoticeMessage);
  }

  @OpsOperationReqLog(value = "上下架-系统公告通知消息")
  @GetMapping("/off/shelf/{id}/{offShelf}")
  public void offShelf(@PathVariable("id") Long id,
      @PathVariable("offShelf") Boolean offShelf) {
    sysNoticeMessageService.offShelf(id, offShelf);
  }

  @OpsOperationReqLog(value = "发布公告-系统公告通知消息")
  @GetMapping("/announcement/{id}")
  public void announcement(@PathVariable("id") Long id) {
    sysNoticeMessageService.announcement(id);
  }

}
