package chatrecords

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

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

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

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

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

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

	rows, err := l.svcCtx.DB.ChatRecords.Delete().Where(chatrecords.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{
		Code: 0,
		Msg:  msg,
	}, nil
}
