// 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/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/predicate"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data/ent/workflowcontractversion"
)

// WorkflowContractVersionDelete is the builder for deleting a WorkflowContractVersion entity.
type WorkflowContractVersionDelete struct {
	config
	hooks    []Hook
	mutation *WorkflowContractVersionMutation
}

// Where appends a list predicates to the WorkflowContractVersionDelete builder.
func (wcvd *WorkflowContractVersionDelete) Where(ps ...predicate.WorkflowContractVersion) *WorkflowContractVersionDelete {
	wcvd.mutation.Where(ps...)
	return wcvd
}

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

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

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

// WorkflowContractVersionDeleteOne is the builder for deleting a single WorkflowContractVersion entity.
type WorkflowContractVersionDeleteOne struct {
	wcvd *WorkflowContractVersionDelete
}

// Where appends a list predicates to the WorkflowContractVersionDelete builder.
func (wcvdo *WorkflowContractVersionDeleteOne) Where(ps ...predicate.WorkflowContractVersion) *WorkflowContractVersionDeleteOne {
	wcvdo.wcvd.mutation.Where(ps...)
	return wcvdo
}

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

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