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

// CumulativeMetricsDelete is the builder for deleting a CumulativeMetrics entity.
type CumulativeMetricsDelete struct {
	config
	hooks    []Hook
	mutation *CumulativeMetricsMutation
}

// Where appends a list predicates to the CumulativeMetricsDelete builder.
func (cmd *CumulativeMetricsDelete) Where(ps ...predicate.CumulativeMetrics) *CumulativeMetricsDelete {
	cmd.mutation.Where(ps...)
	return cmd
}

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

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

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

// CumulativeMetricsDeleteOne is the builder for deleting a single CumulativeMetrics entity.
type CumulativeMetricsDeleteOne struct {
	cmd *CumulativeMetricsDelete
}

// Where appends a list predicates to the CumulativeMetricsDelete builder.
func (cmdo *CumulativeMetricsDeleteOne) Where(ps ...predicate.CumulativeMetrics) *CumulativeMetricsDeleteOne {
	cmdo.cmd.mutation.Where(ps...)
	return cmdo
}

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

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