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

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.app.AppUserIdCmd;
import com.red.circle.framework.web.controller.BaseController;
import com.red.circle.other.app.dto.clientobject.family.*;
import com.red.circle.other.app.dto.clientobject.room.RoomVoiceProfileCO;
import com.red.circle.other.app.dto.cmd.family.*;
import com.red.circle.other.app.service.family.FamilyService;
import com.red.circle.framework.dto.PageResult;
import java.math.BigDecimal;
import java.util.List;
import lombok.RequiredArgsConstructor;
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;

/**
 * 家族管理
 */
@RequiredArgsConstructor
@RestController
@RequestMapping(value = "/family", produces = MediaType.APPLICATION_JSON_VALUE)
public class FamilyRestController extends BaseController {

  private final FamilyService familyService;

  /**
   * 家族列表.
   */
  @GetMapping("/list")
  public PageResult<FamilyListCO> familyList(FamilyListCmd cmd) {
    return familyService.familyList(cmd);
  }

  /**
   * 创建家族.
   */
  @PostMapping("/create")
  public Long create(@RequestBody @Validated FamilyCreateCmd cmd) {
    return familyService.create(cmd);
  }

  /**
   * 编辑家族信息.
   */
  @PostMapping("/edit")
  public void edit(@RequestBody @Validated FamilyInfoEditCmd cmd) {
    familyService.edit(cmd);
  }

  /**
   * 家族基本信息
   */
  @GetMapping("/base-info")
  public FamilyBaseInfoCO getBaseInfo(FamilyBaseInfoQueryCmd cmd) {
    return familyService.getBaseInfo(cmd);
  }

  /**
   * 用户家族基本信息
   */
  @GetMapping("/user-base-info")
  public FamilyBaseInfoCO getBaseInfo(AppUserIdCmd cmd) {
    return familyService.getUserBaseInfo(cmd);
  }

  /**
   * 申请加入家族.
   */
  @PostMapping("/apply-join")
  public void applyJoin(@RequestBody @Validated ApplyJoinFamilyCmd cmd) {
    familyService.applyJoin(cmd);
  }

  /**
   * 家族消息处理.
   */
  @PostMapping("/message/handle")
  public void messageHandle(@RequestBody @Validated FamilyMessageHandleCmd cmd) {
    familyService.messageHandle(cmd);
  }

  /**
   * 家族消息列表.
   */
  @GetMapping("/list/message")
  public List<FamilyMsgListCO> listMessage(FamilyMessageListCmd cmd) {
    return familyService.listMessage(cmd);
  }

  /**
   * 我的家族申请列表.
   */
  @GetMapping("/my-apply-list")
  public List<MyFamilyApplyCO> myApplyList(MyFamilyApplyListCmd cmd) {
    return familyService.myApplyList(cmd);
  }

  /**
   * 取消家族申请.
   */
  @PostMapping("/cancel-apply")
  public void cancelApply(@RequestBody @Validated CancelFamilyApplyCmd cmd) {
    familyService.cancelFamilyApply(cmd);
  }

  /**
   * 重新申请家族.
   */
  @PostMapping("/reapply")
  public void reapply(@RequestBody @Validated ReapplyFamilyCmd cmd) {
    familyService.reapplyFamily(cmd);
  }

  /**
   * 家族成员信息
   */
  @GetMapping("/list/member")
  public FamilyMemberListCO listMember(FamilyMemberListQueryCmd cmd) {
    return familyService.listMember(cmd);
  }

  /**
   * 授权用户家族权限
   */
  @PostMapping("/grant-user-role")
  public void grantUserRole(@RequestBody FamilyGrantUserRoleCmd cmd) {
    familyService.grantUserRole(cmd);
  }

  /**
   * 家族成员Top10周排行榜
   */
  @GetMapping("/member-top10")
  public FamilyLeaderboardCO getMemberTop10(FamilyBaseInfoQueryCmd cmd) {
    return familyService.getLeaderboard(cmd);
  }

  /**
   * 家族成员Top100总排行榜
   */
  @GetMapping("/member-top100")
  public FamilyLeaderboardCO getMemberTop100(FamilyBaseInfoQueryCmd cmd) {
    return familyService.getMemberTop100(cmd);
  }

  /**
   * 家族等级配置
   */
  @GetMapping("/list/level-config")
  public List<FamilyLevelCO> listLevelConfig(AppExtCommand cmd) {
    return familyService.listLevelConfig(cmd);
  }

  /**
   * 首页家族列表.
   */
  @GetMapping("/home-list")
  public PageResult<FamilyHomeListCO> familyHomeList(FamilyHomeListCmd cmd) {
    return familyService.familyHomeList(cmd);
  }

  /**
   * 家族动态列表
   */
  @GetMapping("/news/list")
  public PageResult<FamilyNewsCO> familyNewsList(FamilyNewsListCmd cmd) {
    return familyService.familyNewsList(cmd);
  }

  /**
   * 家族在线房间.
   *
   * @eo.name 家族在线房间.
   * @eo.url /list/online-room
   * @eo.method get
   * @eo.request-type formdata
   */
//  @GetMapping("/list/online-room")
  public List<RoomVoiceProfileCO> listOnlineRoom(@Validated FamilyOnlineRoomQueryCmd cmd) {
    return familyService.listOnlineRoom(cmd);
  }

  /**
   * 将移除家族用户.
   *
   * @eo.name 将移除家族用户.
   * @eo.url /remove-user
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/remove-user")
  public void removeUser(FamilyRemoveUserCmd cmd) {
    familyService.removeUser(cmd);
  }

  /**
   * 用户主动退出家族.
   *
   * @eo.name 用户主动退出家族.
   * @eo.url /user-exit
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/user-exit")
  public void userExit(AppExtCommand cmd) {
    familyService.userExit(cmd);
  }

  /**
   * 解散家族.
   *
   * @eo.name 解散家族.
   * @eo.url /disband
   * @eo.method post
   * @eo.request-type json
   */
  @PostMapping("/disband")
  public void disbandFamily(@RequestBody @Validated DisbandFamilyCmd cmd) {
    familyService.disbandFamily(cmd);
  }

  /**
   * 投入宝箱金币.
   */
  @PostMapping("/box/contribute")
  public void boxContribute(@RequestBody FamilyBaseInfoQueryCmd cmd) {
    familyService.boxContribute(cmd);
  }

  /**
   * 领取宝箱奖励.
   */
  @PostMapping("/box/claim")
  public void boxClaim(@RequestBody @Validated FamilyBoxClaimCmd cmd) {
    familyService.boxClaim(cmd);
  }

  /**
   * 成员在家族中的基本信息.
   *
   * @eo.name 成员在家族中的基本信息.
   * @eo.url /member-user-info
   * @eo.method get
   * @eo.request-type formdata
   */
//  @GetMapping("/member-user-info")
  public FamilyUserInfoCO memberUserInfo(@Validated FamilyUserInfoQueryCmd cmd) {
    return familyService.memberUserInfo(cmd);
  }

  /**
   * 创建家族规则条件.
   *
   * @eo.name 创建家族规则条件.
   * @eo.url /family-create-rule
   * @eo.method get
   * @eo.request-type formdata
   */
//  @GetMapping("/family-create-rule")
  public FamilyCreateRulesCO familyCreateRule(AppExtCommand cmd) {
    return familyService.familyCreateRule(cmd);
  }

  /**
   * give 我的家族宝箱奖励.
   *
   * @eo.name give 我的家族宝箱奖励.
   * @eo.url /my-family-reward
   * @eo.method get
   * @eo.request-type formdata
   */
//  @GetMapping("/my-family-reward")
  public FamilyRewardCO myFamilyReward(AppExtCommand cmd) {
    return familyService.myFamilyReward(cmd);
  }

  /**
   * 领取我的家族宝箱奖励.
   *
   * @eo.name 领取我的家族宝箱奖励.
   * @eo.url /receive-award
   * @eo.method post
   * @eo.request-type json
   */
//  @PostMapping("/receive-award")
  public void receiveAward(@RequestBody @Validated ReceiveFamilyAwardCmd cmd) {
    familyService.receiveFamilyAward(cmd);
  }

  /**
   * 解锁家族群聊.
   *
   * @eo.name 解锁家族群聊.
   * @eo.url /purchasing/group-chat
   * @eo.method post
   * @eo.request-type json
   */
//  @PostMapping("/purchasing/group-chat")
  public BigDecimal purchasingFamilyGroupChat(@RequestBody @Validated FamilyGroupChatQueryCmd cmd) {
    return familyService.purchasingFamilyGroupChat(cmd);
  }

  /**
   * 解散-家族群聊.
   */
//  @PostMapping("/dismiss/group-chat")
  public void dismissFamilyGroupChat(@RequestBody FamilyGroupChatQueryCmd cmd) {

    familyService.dismissFamilyGroupChat(cmd);
  }

  /**
   * 家族群聊是否解锁.
   *
   * @eo.name 家族群聊是否解锁.
   * @eo.url /group/chat/exists
   * @eo.method get
   * @eo.request-type json
   */
//  @GetMapping("/group/chat/exists")
  public Boolean getFamilyGroupChatIsPay(@Validated FamilyGroupChatPayCheckCmd cmd) {
    return familyService.getFamilyGroupChatIsPay(cmd);
  }

}
