package com.red.circle.other.adapter.app.dynamic;


import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.red.circle.common.business.dto.cmd.AppExtCommand;
import com.red.circle.common.business.dto.cmd.IdLongCmd;
import com.red.circle.common.business.dto.cmd.app.AppIdLongCmd;
import com.red.circle.framework.web.controller.BaseController;
import com.red.circle.other.app.dto.clientobject.dynamic.DynamicCommentListCO;
import com.red.circle.other.app.dto.clientobject.dynamic.DynamicListCO;
import com.red.circle.other.app.dto.clientobject.dynamic.DynamicMessageListCO;
import com.red.circle.other.app.dto.clientobject.dynamic.DynamicSendRestrictCO;
import com.red.circle.other.app.dto.clientobject.dynamic.DynamicTagCO;
import com.red.circle.other.app.dto.cmd.dynamic.DynamicByTagLimitCmd;
import com.red.circle.other.app.dto.cmd.dynamic.DynamicCommentCmd;
import com.red.circle.other.app.dto.cmd.dynamic.DynamicCommentLimitCmd;
import com.red.circle.other.app.dto.cmd.dynamic.DynamicContentAddCmd;
import com.red.circle.other.app.dto.cmd.dynamic.DynamicLikeCmd;
import com.red.circle.other.app.dto.cmd.dynamic.DynamicLimitCmd;
import com.red.circle.other.app.dto.cmd.dynamic.DynamicMyLimitCmd;
import com.red.circle.other.app.dto.cmd.dynamic.DynamicReportCmd;
import com.red.circle.other.app.service.dynamic.DynamicService;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
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;

/**
 * <p>
 * 动态 前端控制器.
 * </p>
 *
 * @author pengshigang
 * @eo.api-type http
 * @eo.groupName 动态服务
 * @eo.path /dynamic
 * @since 2022-04-14
 */
@Slf4j
@RestController
@RequestMapping(value = "/dynamic", produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
public class DynamicRestController extends BaseController {

  private final DynamicService dynamicService;

  /**
   * 创建动态.
   *
   * @eo.name 创建动态.
   * @eo.url /create
   * @eo.method post
   * @eo.request-type json
   */
  @PostMapping("/create")
  @JsonSerialize(using = ToStringSerializer.class)
  public Long create(@RequestBody @Validated DynamicContentAddCmd cmd) {
    return dynamicService.createDynamic(cmd);
  }

  /**
   * 删除动态.
   *
   * @eo.name 删除动态.
   * @eo.url /delete
   * @eo.method post
   * @eo.request-type json
   */
  @PostMapping("/delete")
  public void delete(@RequestBody @Validated IdLongCmd cmd) {
    dynamicService.deleteDynamic(cmd);
  }

  /**
   * 动态评论列表.
   *
   * @eo.name 动态评论列表.
   * @eo.url /list/comment
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/list/comment")
  public List<DynamicCommentListCO> listDynamicComment(@Validated DynamicCommentLimitCmd cmd) {
    return dynamicService.listDynamicComment(cmd);
  }

  /**
   * 动态内容详情.
   *
   * @eo.name 动态内容详情.
   * @eo.url /details
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/details")
  public DynamicListCO details(@Validated IdLongCmd cmd) {
    return dynamicService.getDynamicDetails(cmd);
  }

  /**
   * 动态关注列表.
   *
   * @eo.name 动态关注列表.
   * @eo.url /list/follow
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/list/follow")
  public List<DynamicListCO> listDynamicFollow(@Validated DynamicLimitCmd cmd) {
    return dynamicService.listDynamicFollow(cmd);
  }

  /**
   * 我的动态列表.
   *
   * @eo.name 我的动态列表.
   * @eo.url /my/list
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/my/list")
  public List<DynamicListCO> listMyDynamic(@Validated DynamicMyLimitCmd cmd) {
    return dynamicService.listMyDynamic(cmd);
  }

  /**
   * 最新动态列表.
   *
   * @eo.name 最新动态列表.
   * @eo.url /list/latest
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/list/latest")
  public List<DynamicListCO> listDynamicLatest(@Validated DynamicLimitCmd cmd) {
    return dynamicService.listDynamicLatest(cmd);
  }

  /**
   * 热门动态列表.
   *
   * @eo.name 热门动态列表.
   * @eo.url /list/popular
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/list/popular")
  public List<DynamicListCO> listDynamicPopular(@Validated DynamicLimitCmd cmd) {
    return dynamicService.listDynamicPopular(cmd);
  }

  /**
   * 根据标签id查询动态列表.
   *
   * @eo.name 根据标签id查询动态列表.
   * @eo.url /list/by/tag
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/list/by/tag")
  public List<DynamicListCO> listDynamicByTagId(@Validated DynamicByTagLimitCmd cmd) {
    return dynamicService.listDynamicByTagId(cmd);
  }

  /**
   * 标签列表.
   *
   * @eo.name 标签列表.
   * @eo.url /list/tag
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/list/tag")
  public List<DynamicTagCO> listDynamicTag(AppExtCommand cmd) {
    return dynamicService.listDynamicTag(cmd);
  }

  /**
   * 删除评论.
   *
   * @eo.name 删除评论.
   * @eo.url /delete/comment
   * @eo.method post
   * @eo.request-type json
   */
  @PostMapping("/delete/comment")
  public String deleteComment(@RequestBody @Validated AppIdLongCmd cmd) {
    return dynamicService.deleteComment(cmd);
  }

  /**
   * 评论动态或回复用户.
   *
   * @return 数量
   * @eo.name 评论动态或回复用户.
   * @eo.url /comment
   * @eo.method post
   * @eo.request-type json
   */
  @PostMapping("/comment")
  public String comment(@RequestBody @Validated DynamicCommentCmd cmd) {
    return dynamicService.comment(cmd);
  }

  /**
   * 点赞评论.
   *
   * @return 数量
   * @eo.name 点赞评论.
   * @eo.url /like/comment
   * @eo.method post
   * @eo.request-type json
   */
  @PostMapping("/like/comment")
  public String likeComment(@RequestBody @Validated DynamicLikeCmd cmd) {
    return dynamicService.likeComment(cmd);
  }


  /**
   * 点赞动态.
   *
   * @return 数量
   * @eo.name 点赞动态.
   * @eo.url /like
   * @eo.method post
   * @eo.request-type json
   */
  @PostMapping("/like")
  public String likeDynamic(@RequestBody @Validated DynamicLikeCmd cmd) {
    return dynamicService.likeDynamic(cmd);
  }

  /**
   * 我的消息列表.
   *
   * @eo.name 我的消息列表.
   * @eo.url /list/message
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/list/message")
  public List<DynamicMessageListCO> listDynamicMessage(@Validated DynamicLimitCmd cmd) {
    return dynamicService.listDynamicMessage(cmd);
  }

  /**
   * 删除自己全部消息.
   *
   * @eo.name 删除自己全部消息.
   * @eo.url /delete/message/all
   * @eo.method post
   * @eo.request-type formdata
   */
  @PostMapping("/delete/message/all")
  public void deleteMessageAll(AppExtCommand cmd) {
    dynamicService.deleteMessageAll(cmd);
  }

  /**
   * 将我的消息设置为已读.
   *
   * @eo.name 将我的消息设置为已读.
   * @eo.url /message/update/read
   * @eo.method post
   * @eo.request-type formdata
   */
  @PostMapping("/message/update/read")
  public void updateReadMessage(AppExtCommand cmd) {
    dynamicService.updateReadMessage(cmd);
  }

  /**
   * 删除消息.
   *
   * @eo.name 删除消息.
   * @eo.url /delete/message
   * @eo.method post
   * @eo.request-type json
   */
  @PostMapping("/delete/message")
  public void deleteMessage(@RequestBody @Validated IdLongCmd cmd) {
    dynamicService.deleteMessage(cmd);
  }

  /**
   * 根据标签id获得标签.
   *
   * @eo.name 根据标签id获得标签.
   * @eo.url /tag
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/tag")
  public DynamicTagCO getDynamicTag(@Validated IdLongCmd cmd) {
    return dynamicService.getDynamicTag(cmd);
  }

  /**
   * 举报.
   *
   * @eo.name 举报.
   * @eo.url /report
   * @eo.method post
   * @eo.request-type json
   */
  @PostMapping("/report")
  public void report(@RequestBody @Validated DynamicReportCmd cmd) {
    dynamicService.report(cmd);
  }

  /**
   * 校验发送动态权限.
   *
   * @eo.name 校验发送动态权限.
   * @eo.url /check/send/permission
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/check/send/permission")
  public DynamicSendRestrictCO checkSendPermission(AppExtCommand cmd) {
    return dynamicService.checkSendPermission(cmd);
  }

}
