package handler

import (
	"youngee_b_api/consts"
	"youngee_b_api/db"
	"youngee_b_api/middleware"
	"youngee_b_api/model/http_model"
	"youngee_b_api/util"

	"github.com/sirupsen/logrus"

	"github.com/gin-gonic/gin"
)

func WrapEnterpriseBalanceHandler(ctx *gin.Context) {
	handler := newEnterpriseBalanceHandler(ctx)
	baseRun(handler)
}

func newEnterpriseBalanceHandler(ctx *gin.Context) *EnterpriseBalanceHandler {
	return &EnterpriseBalanceHandler{
		req:  http_model.NewEnterpriseBalanceRequest(),
		resp: http_model.NewEnterpriseBalanceResponse(),
		ctx:  ctx,
	}
}

type EnterpriseBalanceHandler struct {
	req  *http_model.EnterpriseBalanceRequest
	resp *http_model.CommonResponse
	ctx  *gin.Context
}

func (e *EnterpriseBalanceHandler) getContext() *gin.Context {
	return e.ctx
}

func (e *EnterpriseBalanceHandler) getResponse() interface{} {
	return e.resp
}

func (e *EnterpriseBalanceHandler) getRequest() interface{} {
	return e.req
}

func (e *EnterpriseBalanceHandler) run() {
	enterpriseID := middleware.GetSessionAuth(e.ctx).EnterpriseID
	logrus.Println(enterpriseID)
	data, err := db.GetEnterpriseBalance(e.ctx, enterpriseID)
	if err != nil {
		logrus.WithContext(e.ctx).Errorf("[FullProjectListHandler] error GetFullProjectList, err:%+v", err)
		util.HandlerPackErrorResp(e.resp, consts.ErrorInternal, consts.DefaultToast)
		return
	}
	e.resp.Data = data
}

func (e *EnterpriseBalanceHandler) checkParam() error {
	return nil
}
