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 WrapGetProviceHandler(ctx *gin.Context) {
	handler := newGetProviceHandler(ctx)
	baseRun(handler)
}

type GetProvice struct {
	ctx  *gin.Context
	req  *http_model.GetProviceRequest
	resp *http_model.CommonResponse
}

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

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

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

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

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

func newGetProviceHandler(ctx *gin.Context) *GetProvice {
	return &GetProvice{
		ctx:  ctx,
		req:  http_model.NewGetProviceRequest(),
		resp: http_model.NewGetProviceResponse(),
	}
}
