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

import com.red.circle.common.business.core.ControllerRedisKeyConstant;
import com.red.circle.framework.web.controller.BaseController;
import com.red.circle.other.app.dto.clientobject.room.RoomMemberUserCO;
import com.red.circle.other.app.dto.cmd.room.RoomMemberIdentityCmd;
import com.red.circle.other.app.dto.cmd.room.RoomMemberQryCmd;
import com.red.circle.other.app.service.room.RoomMemberAppService;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Caching;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
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 penglinag on 2023/9/22
 * @eo.api-type http
 * @eo.groupName 直播服务.成员管理
 * @eo.path /room/member
 */
@RequiredArgsConstructor
@Slf4j
@RestController
@RequestMapping(value = "/room/member", produces = MediaType.APPLICATION_JSON_VALUE)
public class RoomMemberRestController extends BaseController {

  private final RoomMemberAppService roomMemberAppService;

  /**
   * 成员列表.
   *
   * @eo.name 成员列表.
   * @eo.url
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping
  public List<RoomMemberUserCO> listRoomMember(RoomMemberQryCmd cmd) {
    return roomMemberAppService.listRoomMember(cmd);
  }

  /**
   * 身份变更v2.
   *
   * @eo.name 身份变更v2.
   * @eo.url /change-role
   * @eo.method put
   * @eo.request-type json
   */
  @Caching(evict = {
      @CacheEvict(value = ControllerRedisKeyConstant.ROOM_JOINED_LIST, key = "#cmd.requiredReqUserId()")
  })
  @PutMapping("/change-role")
  public void changeRole(@RequestBody @Validated RoomMemberIdentityCmd cmd) {
    roomMemberAppService.changeRole(cmd);
  }

  /**
   * 发出加入邀请.
   *
   * @eo.name 发出加入邀请.
   * @eo.url /join/invite-check
   * @eo.method put
   * @eo.request-type json
   */
//  @RequestVerifySign
//  @ResponseSign
  @PutMapping("/join/invite-check")
  public Boolean joinRoomInviteCheck(@RequestBody @Validated RoomMemberIdentityCmd cmd) {
    return roomMemberAppService.joinRoomInviteCheck(cmd);
  }

}
