// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"galileo/ent/container"
	"galileo/ent/predicate"

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

// ContainerDelete is the builder for deleting a Container entity.
type ContainerDelete struct {
	config
	hooks    []Hook
	mutation *ContainerMutation
}

// Where appends a list predicates to the ContainerDelete builder.
func (cd *ContainerDelete) Where(ps ...predicate.Container) *ContainerDelete {
	cd.mutation.Where(ps...)
	return cd
}

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

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

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

// ContainerDeleteOne is the builder for deleting a single Container entity.
type ContainerDeleteOne struct {
	cd *ContainerDelete
}

// Where appends a list predicates to the ContainerDelete builder.
func (cdo *ContainerDeleteOne) Where(ps ...predicate.Container) *ContainerDeleteOne {
	cdo.cd.mutation.Where(ps...)
	return cdo
}

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

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