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

// PreimageRequestDelete is the builder for deleting a PreimageRequest entity.
type PreimageRequestDelete struct {
	config
	hooks    []Hook
	mutation *PreimageRequestMutation
}

// Where appends a list predicates to the PreimageRequestDelete builder.
func (prd *PreimageRequestDelete) Where(ps ...predicate.PreimageRequest) *PreimageRequestDelete {
	prd.mutation.Where(ps...)
	return prd
}

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

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

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

// PreimageRequestDeleteOne is the builder for deleting a single PreimageRequest entity.
type PreimageRequestDeleteOne struct {
	prd *PreimageRequestDelete
}

// Where appends a list predicates to the PreimageRequestDelete builder.
func (prdo *PreimageRequestDeleteOne) Where(ps ...predicate.PreimageRequest) *PreimageRequestDeleteOne {
	prdo.prd.mutation.Where(ps...)
	return prdo
}

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

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