// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"example/myco-api/ent/predicate"
	"example/myco-api/ent/sporesyringe"

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

// SporeSyringeDelete is the builder for deleting a SporeSyringe entity.
type SporeSyringeDelete struct {
	config
	hooks    []Hook
	mutation *SporeSyringeMutation
}

// Where appends a list predicates to the SporeSyringeDelete builder.
func (ssd *SporeSyringeDelete) Where(ps ...predicate.SporeSyringe) *SporeSyringeDelete {
	ssd.mutation.Where(ps...)
	return ssd
}

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

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

func (ssd *SporeSyringeDelete) sqlExec(ctx context.Context) (int, error) {
	_spec := &sqlgraph.DeleteSpec{
		Node: &sqlgraph.NodeSpec{
			Table: sporesyringe.Table,
			ID: &sqlgraph.FieldSpec{
				Type:   field.TypeInt,
				Column: sporesyringe.FieldID,
			},
		},
	}
	if ps := ssd.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	affected, err := sqlgraph.DeleteNodes(ctx, ssd.driver, _spec)
	if err != nil && sqlgraph.IsConstraintError(err) {
		err = &ConstraintError{msg: err.Error(), wrap: err}
	}
	ssd.mutation.done = true
	return affected, err
}

// SporeSyringeDeleteOne is the builder for deleting a single SporeSyringe entity.
type SporeSyringeDeleteOne struct {
	ssd *SporeSyringeDelete
}

// Where appends a list predicates to the SporeSyringeDelete builder.
func (ssdo *SporeSyringeDeleteOne) Where(ps ...predicate.SporeSyringe) *SporeSyringeDeleteOne {
	ssdo.ssd.mutation.Where(ps...)
	return ssdo
}

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

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