// 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/buildbarn/bb-portal/ent/gen/ent/outputgroup"
	"github.com/buildbarn/bb-portal/ent/gen/ent/predicate"
)

// OutputGroupDelete is the builder for deleting a OutputGroup entity.
type OutputGroupDelete struct {
	config
	hooks    []Hook
	mutation *OutputGroupMutation
}

// Where appends a list predicates to the OutputGroupDelete builder.
func (ogd *OutputGroupDelete) Where(ps ...predicate.OutputGroup) *OutputGroupDelete {
	ogd.mutation.Where(ps...)
	return ogd
}

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

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

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

// OutputGroupDeleteOne is the builder for deleting a single OutputGroup entity.
type OutputGroupDeleteOne struct {
	ogd *OutputGroupDelete
}

// Where appends a list predicates to the OutputGroupDelete builder.
func (ogdo *OutputGroupDeleteOne) Where(ps ...predicate.OutputGroup) *OutputGroupDeleteOne {
	ogdo.ogd.mutation.Where(ps...)
	return ogdo
}

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

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