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

import com.red.circle.framework.core.asserts.ResponseAssert;
import com.red.circle.framework.core.response.ResponseErrorCode;
import com.red.circle.other.app.service.party3rd.TencentCloudService;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
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;

/**
 * 腾讯云.
 *
 * @author pengliang on 2020/4/2 14:35
 * @eo.api-type http
 * @eo.groupName 第三方服务.腾讯云
 * @eo.path /party3rd/tencent/cloud
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping(value = "/party3rd/tencent/cloud", produces = MediaType.APPLICATION_JSON_VALUE)
public class TencentCloudRestController {

  private final TencentCloudService tencentCloudService;

  /**
   * IM回调.
   *
   * @param body {eo.required}
   * @eo.name IM回调.
   * @eo.url /im/callback
   * @eo.method post
   * @eo.request-type json
   */
  @PostMapping("/im/callback")
  public void imCallback(@RequestBody byte[] body) {
    ResponseAssert
        .isTrue(ResponseErrorCode.REQUEST_PARAMETER_ERROR,
            Objects.nonNull(body) && body.length > 0);
    tencentCloudService.imCallback(new String(body));
  }

  /**
   * trtc房间.
   *
   * @param event {eo.required}
   * @eo.name trtc房间.
   * @eo.url /trtc/callback
   * @eo.method post
   * @eo.request-type json
   */
  @PostMapping("/trtc/callback")
  public void trtcCallback(@RequestBody byte[] event) {
    tencentCloudService.trtcCallBack(event);
  }

}
