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

// NetworkMetricsDelete is the builder for deleting a NetworkMetrics entity.
type NetworkMetricsDelete struct {
	config
	hooks    []Hook
	mutation *NetworkMetricsMutation
}

// Where appends a list predicates to the NetworkMetricsDelete builder.
func (nmd *NetworkMetricsDelete) Where(ps ...predicate.NetworkMetrics) *NetworkMetricsDelete {
	nmd.mutation.Where(ps...)
	return nmd
}

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

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

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

// NetworkMetricsDeleteOne is the builder for deleting a single NetworkMetrics entity.
type NetworkMetricsDeleteOne struct {
	nmd *NetworkMetricsDelete
}

// Where appends a list predicates to the NetworkMetricsDelete builder.
func (nmdo *NetworkMetricsDeleteOne) Where(ps ...predicate.NetworkMetrics) *NetworkMetricsDeleteOne {
	nmdo.nmd.mutation.Where(ps...)
	return nmdo
}

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

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