// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"wechat-api/ent/labelrelationship"
	"wechat-api/ent/predicate"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
)

// LabelRelationshipDelete is the builder for deleting a LabelRelationship entity.
type LabelRelationshipDelete struct {
	config
	hooks    []Hook
	mutation *LabelRelationshipMutation
}

// Where appends a list predicates to the LabelRelationshipDelete builder.
func (lrd *LabelRelationshipDelete) Where(ps ...predicate.LabelRelationship) *LabelRelationshipDelete {
	lrd.mutation.Where(ps...)
	return lrd
}

// Exec executes the deletion query and returns how many vertices were deleted.
func (lrd *LabelRelationshipDelete) Exec(ctx context.Context) (int, error) {
	return withHooks(ctx, lrd.sqlExec, lrd.mutation, lrd.hooks)
}

// ExecX is like Exec, but panics if an error occurs.
func (lrd *LabelRelationshipDelete) ExecX(ctx context.Context) int {
	n, err := lrd.Exec(ctx)
	if err != nil {
		panic(err)
	}
	return n
}

func (lrd *LabelRelationshipDelete) sqlExec(ctx context.Context) (int, error) {
	_spec := sqlgraph.NewDeleteSpec(labelrelationship.Table, sqlgraph.NewFieldSpec(labelrelationship.FieldID, field.TypeUint64))
	if ps := lrd.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	affected, err := sqlgraph.DeleteNodes(ctx, lrd.driver, _spec)
	if err != nil && sqlgraph.IsConstraintError(err) {
		err = &ConstraintError{msg: err.Error(), wrap: err}
	}
	lrd.mutation.done = true
	return affected, err
}

// LabelRelationshipDeleteOne is the builder for deleting a single LabelRelationship entity.
type LabelRelationshipDeleteOne struct {
	lrd *LabelRelationshipDelete
}

// Where appends a list predicates to the LabelRelationshipDelete builder.
func (lrdo *LabelRelationshipDeleteOne) Where(ps ...predicate.LabelRelationship) *LabelRelationshipDeleteOne {
	lrdo.lrd.mutation.Where(ps...)
	return lrdo
}

// Exec executes the deletion query.
func (lrdo *LabelRelationshipDeleteOne) Exec(ctx context.Context) error {
	n, err := lrdo.lrd.Exec(ctx)
	switch {
	case err != nil:
		return err
	case n == 0:
		return &NotFoundError{labelrelationship.Label}
	default:
		return nil
	}
}

// ExecX is like Exec, but panics if an error occurs.
func (lrdo *LabelRelationshipDeleteOne) ExecX(ctx context.Context) {
	if err := lrdo.Exec(ctx); err != nil {
		panic(err)
	}
}
