package camel_oil

import (
	"context"

	"github.com/gogf/gf/v2/errors/gcode"
	v1 "kami/api/camel_oil/v1"
	"kami/internal/errHandler"
	"kami/internal/model"
	"kami/internal/service"
)

func (c *ControllerV1) CreateToken(ctx context.Context, req *v1.CreateTokenReq) (res *v1.CreateTokenRes, err error) {
	_, err = service.SysAuth().LoginOnlyLogin(ctx)
	if err != nil {
		err = errHandler.WrapError(ctx, gcode.CodeInternalError, err, "权限不足，只允许核销上传")
		return
	}
	createInput := &model.CamelOilTokenCreateInput{
		Name:                req.Name,
		Phone:               req.Phone,
		Remark:              req.Remark,
		RechargeLimitAmount: req.RechargeLimitAmount,
		RechargeLimitCount:  req.RechargeLimitCount,
	}
	tokenId, err := service.CamelOil().CreateToken(ctx, createInput)
	if err != nil {
		return nil, err
	}

	return &v1.CreateTokenRes{
		TokenId: tokenId,
	}, nil
}
