package com.seer.teach.teacher.controller.app;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import com.seer.teach.common.ResultBean;
import com.seer.teach.common.annotation.DecryptionAnnotation;
import com.seer.teach.common.annotation.EncryptionAnnotation;
import com.seer.teach.common.enums.teacher.LessonStateEnum;
import com.seer.teach.common.enums.teacher.LessonStateEvent;
import com.seer.teach.teacher.common.req.ChatReq;
import com.seer.teach.teacher.common.utils.CountdownExecutorUtil;
import com.seer.teach.teacher.service.AiChatService;
import com.seer.teach.teacher.service.impl.LessonStateMachineService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.statemachine.action.Action;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: Captain
 * @Description: 数字人交流
 * @Date: 2025-06-07 14:38
 */
@Slf4j
@Validated
@RestController
/*@EncryptionAnnotation
@DecryptionAnnotation*/
@RequiredArgsConstructor
@Tag(name = "APP - 数字人交流")
@RequestMapping("/app/chat")
@SaCheckLogin
public class AiChatController {

    private final LessonStateMachineService lessonStateMachineService;

    private final AiChatService aiChatService;

    @PostMapping()
    @Operation(summary = "数字人交流")
    public ResultBean chat(@RequestBody @Validated ChatReq params){
        aiChatService.chat(params);
        return ResultBean.success();
    }

    @GetMapping()
    public ResultBean testAudioWasDown(){
        Integer userId = StpUtil.getLoginIdAsInt();
        lessonStateMachineService.sendEvent(userId, LessonStateEvent.AUDIO_FINISH);
        return ResultBean.success();
    }

}
