// Code generated by ent, DO NOT EDIT.

package serversitemicros

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

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

// DocServerAppDelete is the builder for deleting a DocServerApp entity.
type DocServerAppDelete struct {
	config
	hooks    []Hook
	mutation *DocServerAppMutation
}

// Where appends a list predicates to the DocServerAppDelete builder.
func (dsad *DocServerAppDelete) Where(ps ...predicate.DocServerApp) *DocServerAppDelete {
	dsad.mutation.Where(ps...)
	return dsad
}

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

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

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

// DocServerAppDeleteOne is the builder for deleting a single DocServerApp entity.
type DocServerAppDeleteOne struct {
	dsad *DocServerAppDelete
}

// Where appends a list predicates to the DocServerAppDelete builder.
func (dsado *DocServerAppDeleteOne) Where(ps ...predicate.DocServerApp) *DocServerAppDeleteOne {
	dsado.dsad.mutation.Where(ps...)
	return dsado
}

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

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