// Code generated by ent, DO NOT EDIT.

package serversitemicros

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

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

// DocServerGetProjectDelete is the builder for deleting a DocServerGetProject entity.
type DocServerGetProjectDelete struct {
	config
	hooks    []Hook
	mutation *DocServerGetProjectMutation
}

// Where appends a list predicates to the DocServerGetProjectDelete builder.
func (dsgpd *DocServerGetProjectDelete) Where(ps ...predicate.DocServerGetProject) *DocServerGetProjectDelete {
	dsgpd.mutation.Where(ps...)
	return dsgpd
}

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

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

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

// DocServerGetProjectDeleteOne is the builder for deleting a single DocServerGetProject entity.
type DocServerGetProjectDeleteOne struct {
	dsgpd *DocServerGetProjectDelete
}

// Where appends a list predicates to the DocServerGetProjectDelete builder.
func (dsgpdo *DocServerGetProjectDeleteOne) Where(ps ...predicate.DocServerGetProject) *DocServerGetProjectDeleteOne {
	dsgpdo.dsgpd.mutation.Where(ps...)
	return dsgpdo
}

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

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