// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"demo/ent/enrollment"
	"demo/ent/predicate"

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

// EnrollmentDelete is the builder for deleting a Enrollment entity.
type EnrollmentDelete struct {
	config
	hooks    []Hook
	mutation *EnrollmentMutation
}

// Where appends a list predicates to the EnrollmentDelete builder.
func (ed *EnrollmentDelete) Where(ps ...predicate.Enrollment) *EnrollmentDelete {
	ed.mutation.Where(ps...)
	return ed
}

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

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

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

// EnrollmentDeleteOne is the builder for deleting a single Enrollment entity.
type EnrollmentDeleteOne struct {
	ed *EnrollmentDelete
}

// Where appends a list predicates to the EnrollmentDelete builder.
func (edo *EnrollmentDeleteOne) Where(ps ...predicate.Enrollment) *EnrollmentDeleteOne {
	edo.ed.mutation.Where(ps...)
	return edo
}

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

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