package chatsession

import (
	"net/http"

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

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

// swagger:route post /api/session/list chatsession GetApiSessionList
//
// Get chat session list | 获取ChatSession列表
//
// Get chat session list | 获取ChatSession列表
//
// Parameters:
//  + name: body
//    require: true
//    in: body
//    type: ChatSessionListReq
//
// Responses:
//  200: ChatSessionListResp

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

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