// Code generated by ent, DO NOT EDIT.

package ent

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

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

// LabelTaggingDelete is the builder for deleting a LabelTagging entity.
type LabelTaggingDelete struct {
	config
	hooks    []Hook
	mutation *LabelTaggingMutation
}

// Where appends a list predicates to the LabelTaggingDelete builder.
func (ltd *LabelTaggingDelete) Where(ps ...predicate.LabelTagging) *LabelTaggingDelete {
	ltd.mutation.Where(ps...)
	return ltd
}

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

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

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

// LabelTaggingDeleteOne is the builder for deleting a single LabelTagging entity.
type LabelTaggingDeleteOne struct {
	ltd *LabelTaggingDelete
}

// Where appends a list predicates to the LabelTaggingDelete builder.
func (ltdo *LabelTaggingDeleteOne) Where(ps ...predicate.LabelTagging) *LabelTaggingDeleteOne {
	ltdo.ltd.mutation.Where(ps...)
	return ltdo
}

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

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