package wxcardvisit

import (
	"context"
	"fmt"
	"github.com/zeromicro/go-zero/core/errorx"
	"wechat-api/ent/wxcardvisit"
	"wechat-api/internal/utils/dberrorhandler"

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

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

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

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

func (l *DeleteWxCardVisitLogic) DeleteWxCardVisit(req *types.IDsReq) (*types.BaseMsgResp, error) {
	if len(req.Ids) == 0 {
		return nil, errorx.NewInvalidArgumentError("Ids参数不能为空")
	}
	rows, err := l.svcCtx.DB.WxCardVisit.Delete().Where(wxcardvisit.IDIn(req.Ids...)).Exec(l.ctx)
	if err != nil {
		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
	}
	msg := fmt.Sprintf("delete %v rows", rows)

	return &types.BaseMsgResp{Msg: msg}, nil
}
