// 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/tokenpartialrevocationsecretshare"
)

// TokenPartialRevocationSecretShareDelete is the builder for deleting a TokenPartialRevocationSecretShare entity.
type TokenPartialRevocationSecretShareDelete struct {
	config
	hooks    []Hook
	mutation *TokenPartialRevocationSecretShareMutation
}

// Where appends a list predicates to the TokenPartialRevocationSecretShareDelete builder.
func (tprssd *TokenPartialRevocationSecretShareDelete) Where(ps ...predicate.TokenPartialRevocationSecretShare) *TokenPartialRevocationSecretShareDelete {
	tprssd.mutation.Where(ps...)
	return tprssd
}

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

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

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

// TokenPartialRevocationSecretShareDeleteOne is the builder for deleting a single TokenPartialRevocationSecretShare entity.
type TokenPartialRevocationSecretShareDeleteOne struct {
	tprssd *TokenPartialRevocationSecretShareDelete
}

// Where appends a list predicates to the TokenPartialRevocationSecretShareDelete builder.
func (tprssdo *TokenPartialRevocationSecretShareDeleteOne) Where(ps ...predicate.TokenPartialRevocationSecretShare) *TokenPartialRevocationSecretShareDeleteOne {
	tprssdo.tprssd.mutation.Where(ps...)
	return tprssdo
}

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

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