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

// OrgInvitationDelete is the builder for deleting a OrgInvitation entity.
type OrgInvitationDelete struct {
	config
	hooks    []Hook
	mutation *OrgInvitationMutation
}

// Where appends a list predicates to the OrgInvitationDelete builder.
func (oid *OrgInvitationDelete) Where(ps ...predicate.OrgInvitation) *OrgInvitationDelete {
	oid.mutation.Where(ps...)
	return oid
}

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

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

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

// OrgInvitationDeleteOne is the builder for deleting a single OrgInvitation entity.
type OrgInvitationDeleteOne struct {
	oid *OrgInvitationDelete
}

// Where appends a list predicates to the OrgInvitationDelete builder.
func (oido *OrgInvitationDeleteOne) Where(ps ...predicate.OrgInvitation) *OrgInvitationDeleteOne {
	oido.oid.mutation.Where(ps...)
	return oido
}

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

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