// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
	"github.com/lightsparkdev/spark/so/ent/predicate"
	"github.com/lightsparkdev/spark/so/ent/signingnonce"
)

// SigningNonceDelete is the builder for deleting a SigningNonce entity.
type SigningNonceDelete struct {
	config
	hooks    []Hook
	mutation *SigningNonceMutation
}

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

// Exec executes the deletion query and returns how many vertices were deleted.
func (snd *SigningNonceDelete) 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 *SigningNonceDelete) ExecX(ctx context.Context) int {
	n, err := snd.Exec(ctx)
	if err != nil {
		panic(err)
	}
	return n
}

func (snd *SigningNonceDelete) sqlExec(ctx context.Context) (int, error) {
	_spec := sqlgraph.NewDeleteSpec(signingnonce.Table, sqlgraph.NewFieldSpec(signingnonce.FieldID, field.TypeUUID))
	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
}

// SigningNonceDeleteOne is the builder for deleting a single SigningNonce entity.
type SigningNonceDeleteOne struct {
	snd *SigningNonceDelete
}

// Where appends a list predicates to the SigningNonceDelete builder.
func (sndo *SigningNonceDeleteOne) Where(ps ...predicate.SigningNonce) *SigningNonceDeleteOne {
	sndo.snd.mutation.Where(ps...)
	return sndo
}

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

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