package credit_balance

import (
	"net/http"

	"github.com/zeromicro/go-zero/rest/httpx"

	"wechat-api/internal/logic/credit_balance"
	"wechat-api/internal/svc"
	"wechat-api/internal/types"
)

// swagger:route post /credit_balance/create credit_balance CreateCreditBalance
//
// Create credit balance information | 创建CreditBalance
//
// Create credit balance information | 创建CreditBalance
//
// Parameters:
//  + name: body
//    require: true
//    in: body
//    type: CreditBalanceInfo
//
// Responses:
//  200: BaseMsgResp

func CreateCreditBalanceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		var req types.CreditBalanceInfo
		if err := httpx.Parse(r, &req, true); err != nil {
			httpx.ErrorCtx(r.Context(), w, err)
			return
		}

		l := credit_balance.NewCreateCreditBalanceLogic(r.Context(), svcCtx)
		resp, err := l.CreateCreditBalance(&req)
		if err != nil {
			httpx.ErrorCtx(r.Context(), w, err)
		} else {
			httpx.OkJsonCtx(r.Context(), w, resp)
		}
	}
}
