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

// DynamicExecutionMetricsDelete is the builder for deleting a DynamicExecutionMetrics entity.
type DynamicExecutionMetricsDelete struct {
	config
	hooks    []Hook
	mutation *DynamicExecutionMetricsMutation
}

// Where appends a list predicates to the DynamicExecutionMetricsDelete builder.
func (demd *DynamicExecutionMetricsDelete) Where(ps ...predicate.DynamicExecutionMetrics) *DynamicExecutionMetricsDelete {
	demd.mutation.Where(ps...)
	return demd
}

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

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

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

// DynamicExecutionMetricsDeleteOne is the builder for deleting a single DynamicExecutionMetrics entity.
type DynamicExecutionMetricsDeleteOne struct {
	demd *DynamicExecutionMetricsDelete
}

// Where appends a list predicates to the DynamicExecutionMetricsDelete builder.
func (demdo *DynamicExecutionMetricsDeleteOne) Where(ps ...predicate.DynamicExecutionMetrics) *DynamicExecutionMetricsDeleteOne {
	demdo.demd.mutation.Where(ps...)
	return demdo
}

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

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