package wxcardvisit

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 CreateWxCardVisitLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

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

func (l *CreateWxCardVisitLogic) CreateWxCardVisit(req *types.WxCardVisitReq) (*types.BaseMsgResp, error) {
	err := l.svcCtx.DB.WxCardVisit.Create().
		SetNotNilUserID(req.UserId).
		SetNotNilBotID(req.BotId).
		SetNotNilBotType(req.BotType).
		Exec(l.ctx)
	if err != nil {
		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
	}

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