package chat

import (
	"net/http"

	"github.com/zeromicro/go-zero/rest/httpx"

	"wechat-api/internal/logic/chat"
	"wechat-api/internal/svc"
	"wechat-api/internal/types"
)

// swagger:route post /v1/chat/completions chat ChatCompletions
//

//

//
// Parameters:
//  + name: body
//    require: true
//    in: body
//    type: CompApiReq
//
// Responses:
//  200: CompOpenApiResp

func ChatCompletionsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		var req types.CompApiReq
		if err := httpx.Parse(r, &req, true); err != nil {
			httpx.ErrorCtx(r.Context(), w, err)
			return
		}

		l := chat.NewChatCompletionsLogic(r.Context(), svcCtx)
		resp, err := l.ChatCompletions(&req)
		if err != nil {
			httpx.ErrorCtx(r.Context(), w, err)
		} else {
			httpx.OkJsonCtx(r.Context(), w, resp)
		}
	}
}
