package label_relationship

import (
	"context"
	"wechat-api/ent/labelrelationship"
	"wechat-api/internal/svc"
	"wechat-api/internal/types"
	"wechat-api/internal/utils/dberrorhandler"

	"github.com/suyuan32/simple-admin-common/msg/errormsg"
	"github.com/zeromicro/go-zero/core/logx"
)

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

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

func (l *DeleteLabelRelationshipLogic) DeleteLabelRelationship(req *types.IDsReq) (*types.BaseMsgResp, error) {
	organizationId := l.ctx.Value("organizationId").(uint64)
	_, err := l.svcCtx.DB.LabelRelationship.Delete().Where(labelrelationship.IDIn(req.Ids...), labelrelationship.OrganizationIDEQ(organizationId)).Exec(l.ctx)

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

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