package com.sikey.wa04.api.message.client.rest;

import com.sikey.wa04.business.application.service.message.MessagingPublishService;
import com.sikey.wa04.business.infrastructure.configuration.ProjectContextConstant;
import com.sikey.wa04.business.infrastructure.dto.request.messaging.MessagingAckRequest;
import com.sikey.wa04.business.infrastructure.dto.request.messaging.MessagingPublishRequest;
import com.sikey.wa04.business.infrastructure.dto.response.messaging.MessagingPublishResponse;
import com.sikey.wa04.common.BaseController;
import com.sikey.wa04.common.interceptor.Authenticated;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 消息 Controller
 *
 * @author luoyangwei
 * @date 2024年10月14日16:20:38
 */
@RestController
@RequestMapping(ProjectContextConstant.MESSAGE_URL + "/messaging/publish")
public class ChatMessageController extends BaseController {

    @Resource
    private MessagingPublishService messagingPublishService;

    /**
     * 语聊文本消息
     *
     * @param request 请求
     * @return 响应
     */
    @Authenticated
    @PostMapping("/chat/text")
    public MessagingPublishResponse text(
            @Validated @RequestBody MessagingPublishRequest<MessagingPublishRequest.TextContent> request) {
        request.setHeader(genericManufacturerHeader());
        return messagingPublishService.publish(request);
    }

    /**
     * 语聊视频消息
     *
     * @param request 请求
     * @return 响应
     */
    @Authenticated
    @PostMapping("/chat/video")
    public MessagingPublishResponse video(
            @Validated @RequestBody MessagingPublishRequest<MessagingPublishRequest.VideoContent> request) {
        request.setHeader(genericManufacturerHeader());
        return messagingPublishService.publish(request);
    }

    /**
     * 语聊语音消息
     *
     * @param request 请求
     * @return 响应
     */
    @Authenticated
    @PostMapping("/chat/voice")
    public MessagingPublishResponse voice(
            @Validated @RequestBody MessagingPublishRequest<MessagingPublishRequest.VoiceContent> request) {
        request.setHeader(genericManufacturerHeader());
        return messagingPublishService.publish(request);
    }

    /**
     * 语聊表情消息
     *
     * @param request 请求
     * @return 响应
     */
    @Authenticated
    @PostMapping("/chat/emoji")
    public MessagingPublishResponse emoji(
            @Validated @RequestBody MessagingPublishRequest<MessagingPublishRequest.EmojiContent> request) {
        request.setHeader(genericManufacturerHeader());
        return messagingPublishService.publish(request);
    }

    /**
     * 语聊图片消息
     *
     * @param request 请求
     * @return 响应
     */
    @Authenticated
    @PostMapping("/chat/image")
    public MessagingPublishResponse image(
            @Validated @RequestBody MessagingPublishRequest<MessagingPublishRequest.ImageContent> request) {
        request.setHeader(genericManufacturerHeader());
        return messagingPublishService.publish(request);
    }

    /**
     * 收到消息的应答
     *
     * @return 响应
     */
    @Authenticated
    @GetMapping("/ack")
    public void ack(@Valid MessagingAckRequest request) {
        messagingPublishService.ack(request);
    }
}
