package cn.reghao.tnb.auth.app.controller;

import cn.reghao.tnb.auth.app.model.vo.RtmpPlay;
import cn.reghao.tnb.auth.app.model.vo.RtmpRecord;
import cn.reghao.tnb.auth.app.config.rabbitmq.RabbitProducer;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author reghao
 * @date 2025-09-14 09:46:22
 */
@Tag(name = "nginx-rtmp 回调接口")
@RestController
@RequestMapping("/api/auth/rtmp")
@Slf4j
public class AccountRtmpController {
    private final RabbitProducer rabbitProducer;

    public AccountRtmpController(RabbitProducer rabbitProducer) {
        this.rabbitProducer = rabbitProducer;
    }

    @Operation(summary = "rtmp publish 回调", description = "N")
    @PostMapping(value = "/on_publish", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<String> rtmpOnPublish(RtmpPlay rtmpPlay) {
        rabbitProducer.sendRtmpMessage(rtmpPlay);
        log.info("rtmp publish event...");

        int statusCode = HttpStatus.OK.value();
        int statusCode1 = HttpStatus.UNAUTHORIZED.value();
        String body = "";
        return ResponseEntity.status(statusCode).body(body);
    }

    @Operation(summary = "rtmp publish done 回调", description = "N")
    @PostMapping(value = "/on_publish_done", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<String> rtmpOnPublishDone(RtmpPlay rtmpPlay) {
        rabbitProducer.sendRtmpMessage(rtmpPlay);
        log.info("rtmp publish done event...");

        int statusCode = 200;
        String body = "";
        return ResponseEntity.status(statusCode).body(body);
    }

    @Operation(summary = "rtmp play 回调", description = "N")
    @PostMapping(value = "/on_play", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<String> rtmpOnPlay(RtmpPlay rtmpPlay) {
        rabbitProducer.sendRtmpMessage(rtmpPlay);
        log.info("rtmp play event...");

        int statusCode = 200;
        String body = "";
        return ResponseEntity.status(statusCode).body(body);
    }

    @Operation(summary = "rtmp play done 回调", description = "N")
    @PostMapping(value = "/on_play_done", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<String> rtmpOnPlayDone(RtmpPlay rtmpPlay) {
        rabbitProducer.sendRtmpMessage(rtmpPlay);
        log.info("rtmp play done event...");

        int statusCode = 200;
        String body = "";
        return ResponseEntity.status(statusCode).body(body);
    }

    @Operation(summary = "rtmp record done 回调", description = "N")
    @PostMapping(value = "/on_record_done", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<String> rtmpOnRecordDone(RtmpRecord rtmpRecord) {
        //rabbitProducer.sendRtmpMessage(rtmpPlay);
        log.info("rtmp record done event...");

        int statusCode = 200;
        String body = "";
        return ResponseEntity.status(statusCode).body(body);
    }
}
