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

// SigningKeyshareDelete is the builder for deleting a SigningKeyshare entity.
type SigningKeyshareDelete struct {
	config
	hooks    []Hook
	mutation *SigningKeyshareMutation
}

// Where appends a list predicates to the SigningKeyshareDelete builder.
func (skd *SigningKeyshareDelete) Where(ps ...predicate.SigningKeyshare) *SigningKeyshareDelete {
	skd.mutation.Where(ps...)
	return skd
}

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

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

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

// SigningKeyshareDeleteOne is the builder for deleting a single SigningKeyshare entity.
type SigningKeyshareDeleteOne struct {
	skd *SigningKeyshareDelete
}

// Where appends a list predicates to the SigningKeyshareDelete builder.
func (skdo *SigningKeyshareDeleteOne) Where(ps ...predicate.SigningKeyshare) *SigningKeyshareDeleteOne {
	skdo.skd.mutation.Where(ps...)
	return skdo
}

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

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