// Code generated by ent, DO NOT EDIT.

package ent

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

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

// SopNodeDelete is the builder for deleting a SopNode entity.
type SopNodeDelete struct {
	config
	hooks    []Hook
	mutation *SopNodeMutation
}

// Where appends a list predicates to the SopNodeDelete builder.
func (snd *SopNodeDelete) Where(ps ...predicate.SopNode) *SopNodeDelete {
	snd.mutation.Where(ps...)
	return snd
}

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

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

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

// SopNodeDeleteOne is the builder for deleting a single SopNode entity.
type SopNodeDeleteOne struct {
	snd *SopNodeDelete
}

// Where appends a list predicates to the SopNodeDelete builder.
func (sndo *SopNodeDeleteOne) Where(ps ...predicate.SopNode) *SopNodeDeleteOne {
	sndo.snd.mutation.Where(ps...)
	return sndo
}

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

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