// Code generated by ent, DO NOT EDIT.

package serversitemicros

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

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

// DocServerProjectDelete is the builder for deleting a DocServerProject entity.
type DocServerProjectDelete struct {
	config
	hooks    []Hook
	mutation *DocServerProjectMutation
}

// Where appends a list predicates to the DocServerProjectDelete builder.
func (dspd *DocServerProjectDelete) Where(ps ...predicate.DocServerProject) *DocServerProjectDelete {
	dspd.mutation.Where(ps...)
	return dspd
}

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

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

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

// DocServerProjectDeleteOne is the builder for deleting a single DocServerProject entity.
type DocServerProjectDeleteOne struct {
	dspd *DocServerProjectDelete
}

// Where appends a list predicates to the DocServerProjectDelete builder.
func (dspdo *DocServerProjectDeleteOne) Where(ps ...predicate.DocServerProject) *DocServerProjectDeleteOne {
	dspdo.dspd.mutation.Where(ps...)
	return dspdo
}

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

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