// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"registry-backend/ent/nodereview"
	"registry-backend/ent/predicate"

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

// NodeReviewDelete is the builder for deleting a NodeReview entity.
type NodeReviewDelete struct {
	config
	hooks    []Hook
	mutation *NodeReviewMutation
}

// Where appends a list predicates to the NodeReviewDelete builder.
func (nrd *NodeReviewDelete) Where(ps ...predicate.NodeReview) *NodeReviewDelete {
	nrd.mutation.Where(ps...)
	return nrd
}

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

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

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

// NodeReviewDeleteOne is the builder for deleting a single NodeReview entity.
type NodeReviewDeleteOne struct {
	nrd *NodeReviewDelete
}

// Where appends a list predicates to the NodeReviewDelete builder.
func (nrdo *NodeReviewDeleteOne) Where(ps ...predicate.NodeReview) *NodeReviewDeleteOne {
	nrdo.nrd.mutation.Where(ps...)
	return nrdo
}

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

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