package handler

import (
	"github.com/gin-gonic/gin"
	"github.com/sirupsen/logrus"
	"youngee_b_api/consts"
	"youngee_b_api/db"
	"youngee_b_api/middleware"
	"youngee_b_api/model/http_model"
	"youngee_b_api/util"
)

func WrapGetReceiveInfoHandler(ctx *gin.Context) {
	handler := newGetReceiveInfoHandler(ctx)
	baseRun(handler)
}

type GetReceiveInfoHandler struct {
	ctx  *gin.Context
	req  *http_model.GetReceiveInfoRequest
	resp *http_model.CommonResponse
}

func (g GetReceiveInfoHandler) getContext() *gin.Context {
	return g.ctx
}

func (g GetReceiveInfoHandler) getResponse() interface{} {
	return g.resp
}

func (g GetReceiveInfoHandler) getRequest() interface{} {
	return g.req
}

func (g GetReceiveInfoHandler) run() {
	auth := middleware.GetSessionAuth(g.ctx)
	enterpriseID := auth.EnterpriseID
	data, err := db.GetReceiveInfo(g.ctx, enterpriseID)
	if err != nil {
		// 数据库查询失败，返回5001
		logrus.Errorf("[GetReceiveInfoHandler] call GetReceiveInfo err:%+v\n", err)
		util.HandlerPackErrorResp(g.resp, consts.ErrorInternal, "")
		logrus.Info("GetReceiveInfo fail,req:%+v", g.req)
		return
	}
	g.resp.Data = data
}

func (g GetReceiveInfoHandler) checkParam() error {
	return nil
}

func newGetReceiveInfoHandler(ctx *gin.Context) *GetReceiveInfoHandler {
	return &GetReceiveInfoHandler{
		ctx:  ctx,
		req:  http_model.NewGetReceiveInfoRequest(),
		resp: http_model.NewGetReceiveInfoResponse(),
	}
}
