// Code generated by ent, DO NOT EDIT.

package serversitemicros

import (
	"context"
	"convert-server/domain/entity/serversitemicros/docservercallback"
	"convert-server/domain/entity/serversitemicros/predicate"

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

// DocServerCallbackDelete is the builder for deleting a DocServerCallback entity.
type DocServerCallbackDelete struct {
	config
	hooks    []Hook
	mutation *DocServerCallbackMutation
}

// Where appends a list predicates to the DocServerCallbackDelete builder.
func (dscd *DocServerCallbackDelete) Where(ps ...predicate.DocServerCallback) *DocServerCallbackDelete {
	dscd.mutation.Where(ps...)
	return dscd
}

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

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

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

// DocServerCallbackDeleteOne is the builder for deleting a single DocServerCallback entity.
type DocServerCallbackDeleteOne struct {
	dscd *DocServerCallbackDelete
}

// Where appends a list predicates to the DocServerCallbackDelete builder.
func (dscdo *DocServerCallbackDeleteOne) Where(ps ...predicate.DocServerCallback) *DocServerCallbackDeleteOne {
	dscdo.dscd.mutation.Where(ps...)
	return dscdo
}

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

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