package wxcarduser

import (
	"context"
	"github.com/suyuan32/simple-admin-common/msg/errormsg"
	"wechat-api/internal/utils/dberrorhandler"

	"wechat-api/internal/svc"
	"wechat-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateWxCardUserLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUpdateWxCardUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateWxCardUserLogic {
	return &UpdateWxCardUserLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx}
}

func (l *UpdateWxCardUserLogic) UpdateWxCardUser(req *types.WxCardUserInfo) (*types.BaseMsgResp, error) {
	err := l.svcCtx.DB.WxCardUser.UpdateOneID(*req.Id).
		SetNotNilAccount(req.Account).
		SetNotNilNickname(req.Nickname).
		SetNotNilRemark(req.Remark).
		SetNotNilPhone(req.Phone).
		Exec(l.ctx)
	if err != nil {
		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
	}

	return &types.BaseMsgResp{Msg: errormsg.Success}, nil
}
