package com.sonic.pigeon.controller.api;

import com.sonic.common.rpc.Result;
import com.sonic.pigeon.lib.input.HistoryMessageInput;
import com.sonic.pigeon.lib.input.SendAiCustomerMessageInput;
import com.sonic.pigeon.lib.input.SendAiTextMessageInput;
import com.sonic.pigeon.lib.input.UpdateAiSendCustomImageMessageInput;
import com.sonic.pigeon.lib.output.HistoryMessageOutput;
import com.sonic.pigeon.service.ImMessageService;
import com.sonic.sdk.api.annotation.IgnoreAuth;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * API-IM消息
 * @author coder
 */
@Validated
@RestController
public class ImMessageApi {

    @Autowired
    private ImMessageService imMessageService;

    @IgnoreAuth
    @ApiOperation(value = "发送Im文本消息（ai给用户发）", tags = {"API-IM消息"})
    @PostMapping("/api/im-message/send-ai-to-user-text-message")
    public Result<Void> sendAiToUserTextMessage(@RequestBody @Valid SendAiTextMessageInput input) {
        imMessageService.sendAiToUserTextMessage(input);
        return Result.success();
    }

    @IgnoreAuth
    @ApiOperation(value = "发送Im文本消息（用户给ai发）", tags = {"API-IM消息"})
    @PostMapping("/api/im-message/send-user-to-ai-text-message")
    public Result<Void> sendUserToAiTextMessage(@RequestBody @Valid SendAiTextMessageInput input) {
        imMessageService.sendUserToAiTextMessage(input);
        return Result.success();
    }

    @IgnoreAuth
    @ApiOperation(value = "发送Im自定义消息（ai给用户发）", tags = {"API-IM消息"})
    @PostMapping("/api/im-message/send-ai-to-user-customer-message")
    public Result<Void> sendAiToUserCustomerMessage(@RequestBody @Valid SendAiCustomerMessageInput input) {
        imMessageService.sendAiToUserCustomerMessage(input);
        return Result.success();
    }

    @IgnoreAuth
    @ApiOperation(value = "发送用户的Im自定义消息（用户给AI发）", tags = {"API-IM消息"})
    @PostMapping("/api/im-message/send-user-to-ai-customer-message")
    public Result<Void> sendUserToAiCustomerMessage(@RequestBody @Valid SendAiCustomerMessageInput input) {
        imMessageService.sendUserToAiCustomerMessage(input);
        return Result.success();
    }

    @IgnoreAuth
    @ApiOperation(value = "获取历史消息", tags = {"API-IM消息"})
    @PostMapping("/api/im-message/get-history-message")
    public Result<List<HistoryMessageOutput>> getUserToAiHistoryMessage(@RequestBody @Validated HistoryMessageInput input) {
        return Result.success(imMessageService.getUserToAiHistoryMessage(input));
    }

    @IgnoreAuth
    @ApiOperation(value = "获取历史消息", tags = {"API-IM消息"})
    @PostMapping("/api/im-message/get-ai-to-user-history-message")
    public Result<List<HistoryMessageOutput>> getAiToUserHistoryMessage(@RequestBody @Validated HistoryMessageInput input) {
        return Result.success(imMessageService.getAiToUserHistoryMessage(input));
    }

    @IgnoreAuth
    @ApiOperation(value = "更新自定义图片消息", tags = {"API-IM消息"})
    @PostMapping("/api/im-message/update-ai-custom-image-message")
    public Result<Void> updateAiSendCustomImageMessage(@RequestBody @Validated UpdateAiSendCustomImageMessageInput input) {
        imMessageService.updateAiSendCustomImageMessage(input.getAiId(), input.getUserId(), input.getMessageServerId(), input.getAttachment());
        return Result.success();
    }

}
