package batch_msg

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

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

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

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

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

func (l *RemoveWhatcappBatchMsgLogic) RemoveWhatcappBatchMsg(req *types.IDsReq) (*types.BaseMsgResp, error) {
	_, err := l.svcCtx.DB.BatchMsg.Delete().Where(
		batchmsg.IDIn(req.Ids...),
		batchmsg.CtypeEQ(2),
	).Exec(l.ctx)

	if err != nil {
		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
	}

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