package wxcarduser

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

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

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

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

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

func (l *DeleteWxCardUserLogic) DeleteWxCardUser(req *types.IDsReq) (*types.BaseMsgResp, error) {
	if len(req.Ids) == 0 {
		return nil, errorx.NewInvalidArgumentError("Ids参数不能为空")
	}

	rows, err := l.svcCtx.DB.WxCardUser.Delete().Where(wxcarduser.IDIn(req.Ids...)).Exec(l.ctx)
	if err != nil {
		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
	}
	msg := fmt.Sprintf("delete %d rows", rows)

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