package api_key

import (
	"net/http"

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

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

// swagger:route post /api_key/list api_key GetApiKeyList
//
// Get api_key list | 获取ApiKey列表
//
// Get api_key list | 获取ApiKey列表
//
// Parameters:
//  + name: body
//    require: true
//    in: body
//    type: ApiKeyListReq
//
// Responses:
//  200: ApiKeyListResp

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

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