package label_tagging

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

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

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

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

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

func (l *DeleteLabelTaggingLogic) DeleteLabelTagging(req *types.IDsReq) (resp *types.BaseMsgResp, err error) {
	organizationId := l.ctx.Value("organizationId").(uint64)
	_, err = l.svcCtx.DB.LabelTagging.Delete().Where(labeltagging.IDIn(req.Ids...), labeltagging.OrganizationID(organizationId)).Exec(l.ctx)

	if err != nil {
		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
	}
	l.svcCtx.Rds.Del(l.ctx, "label_tagging_info")
	return &types.BaseMsgResp{Msg: errormsg.DeleteSuccess}, nil
}
