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) UpdateToken(ctx context.Context, req *v1.UpdateTokenReq) (res *v1.UpdateTokenRes, err error) {
	_, err = service.SysAuth().LoginOnlyLogin(ctx)
	if err != nil {
		err = errHandler.WrapError(ctx, gcode.CodeInternalError, err, "登录校验失败")
		return
	}
	err = service.CamelOil().UpdateTokenInfo(ctx, &model.CamelOilTokenUpdateInput{
		TokenId:             req.TokenId,
		Name:                req.Name,
		Remark:              req.Remark,
		RechargeLimitAmount: req.RechargeLimitAmount,
		RechargeLimitCount:  req.RechargeLimitCount,
	})
	if err != nil {
		return nil, err
	}

	return &v1.UpdateTokenRes{
		Message: "Token信息修改成功",
	}, nil
}
