package handler

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

func WrapFindAllSubAccountHandler(ctx *gin.Context) {
	handler := newFindAllSubAccountHandler(ctx)
	baseRun(handler)
}

func newFindAllSubAccountHandler(ctx *gin.Context) *FindAllSubAccountHandler {
	return &FindAllSubAccountHandler{
		req:  http_model.NewFindAllSubAccountRequest(),
		resp: http_model.NewFindAllSubAccountResponse(),
		ctx:  ctx,
	}
}

type FindAllSubAccountHandler struct {
	req  *http_model.FindAllSubAccountRequest
	resp *http_model.CommonResponse
	ctx  *gin.Context
}

func (h *FindAllSubAccountHandler) getRequest() interface{} {
	return h.req
}
func (h *FindAllSubAccountHandler) getContext() *gin.Context {
	return h.ctx
}
func (h *FindAllSubAccountHandler) getResponse() interface{} {
	return h.resp
}
func (h *FindAllSubAccountHandler) run() {
	data, err := service.SubAccount.FindSubAccountByEnterpriseId(h.ctx, *h.req)
	if err != nil {
		logrus.Errorf("[FindSubAccountByEnterpriseId] call SetSession err:%+v\n", err)
		util.HandlerPackErrorResp(h.resp, consts.ErrorInternal, err.Error())
		log.Info("FindSubAccountByEnterpriseId fail,req:%+v", h.req)
		h.resp.Message = err.Error()
		h.resp.Status = 40000
		return
	}
	h.resp.Data = data
	h.resp.Status = 20000
	h.resp.Message = "ok"
}

func (h *FindAllSubAccountHandler) checkParam() error {
	return nil
}
