// 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/lightsparkdev/spark/so/ent/l1tokencreate"
	"github.com/lightsparkdev/spark/so/ent/predicate"
)

// L1TokenCreateDelete is the builder for deleting a L1TokenCreate entity.
type L1TokenCreateDelete struct {
	config
	hooks    []Hook
	mutation *L1TokenCreateMutation
}

// Where appends a list predicates to the L1TokenCreateDelete builder.
func (lcd *L1TokenCreateDelete) Where(ps ...predicate.L1TokenCreate) *L1TokenCreateDelete {
	lcd.mutation.Where(ps...)
	return lcd
}

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

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

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

// L1TokenCreateDeleteOne is the builder for deleting a single L1TokenCreate entity.
type L1TokenCreateDeleteOne struct {
	lcd *L1TokenCreateDelete
}

// Where appends a list predicates to the L1TokenCreateDelete builder.
func (lcdo *L1TokenCreateDeleteOne) Where(ps ...predicate.L1TokenCreate) *L1TokenCreateDeleteOne {
	lcdo.lcd.mutation.Where(ps...)
	return lcdo
}

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

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