package employee

import (
	"net/http"
	jwtutils "wechat-api/internal/utils/jwt"

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

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

// swagger:route post /employee/search employee GetEmployeeSearch
//
// Get employee list | 获取Employee列表
//
// Get employee list | 获取Employee列表
//
// Parameters:
//  + name: body
//    require: true
//    in: body
//    type: EmployeeListReq
//
// Responses:
//  200: EmployeeListResp

func GetEmployeeSearchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		var req types.EmployeeListReq
		if err := httpx.Parse(r, &req, true); err != nil {
			httpx.ErrorCtx(r.Context(), w, err)
			return
		}
		tokenStr := jwtutils.StripBearerPrefixFromToken(r.Header.Get("Authorization"))
		l := employee.NewGetEmployeeSearchLogic(r.Context(), svcCtx)
		resp, err := l.GetEmployeeSearch(&req, tokenStr)
		if err != nil {
			httpx.ErrorCtx(r.Context(), w, err)
		} else {
			httpx.OkJsonCtx(r.Context(), w, resp)
		}
	}
}
