package handler

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

func WrapGetTalentNumHandler(ctx *gin.Context) {
	handler := newGetTalentNumHandler(ctx)
	baseRun(handler)
}

type GetTalentNum struct {
	ctx  *gin.Context
	req  *http_model.GetTalentNumRequest
	resp *http_model.CommonResponse
}

func (c GetTalentNum) getContext() *gin.Context {
	return c.ctx
}

func (c GetTalentNum) getResponse() interface{} {
	return c.resp
}

func (c GetTalentNum) getRequest() interface{} {
	return c.req
}

func (c GetTalentNum) run() {
	data := http_model.GetTalentNumRequest{}
	data = *c.req
	res, err := db.GetTalentNum(c.ctx, data)
	if err != nil {
		logrus.Errorf("[GetTalentNum] call GetTalentNum err:%+v\n", err)
		util.HandlerPackErrorResp(c.resp, consts.ErrorParamCheck, "")
		logrus.Info("GetTalentNum fail,req:%+v", c.req)
		return
	}
	c.resp.Message = "成功查询达人数量"
	c.resp.Data = res
	c.resp.Status = consts.ErrorSuccess
}

func (c GetTalentNum) checkParam() error {
	return nil
}

func newGetTalentNumHandler(ctx *gin.Context) *GetTalentNum {
	return &GetTalentNum{
		ctx:  ctx,
		req:  http_model.NewGetTalentNumRequest(),
		resp: http_model.NewGetTalentNumResponse(),
	}
}
