package wxcard

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

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

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

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

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

func (l *DeleteWxCardLogic) DeleteWxCard(req *types.IDsReq) (*types.BaseMsgResp, error) {
	if len(req.Ids) == 0 {
		return nil, errorx.NewDefaultError("Ids参数不能为空")
	}
	rows, err := l.svcCtx.DB.WxCard.Delete().Where(wxcard.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
}
