// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"wechat-api/ent/agentbase"
	"wechat-api/ent/predicate"

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

// AgentBaseDelete is the builder for deleting a AgentBase entity.
type AgentBaseDelete struct {
	config
	hooks    []Hook
	mutation *AgentBaseMutation
}

// Where appends a list predicates to the AgentBaseDelete builder.
func (abd *AgentBaseDelete) Where(ps ...predicate.AgentBase) *AgentBaseDelete {
	abd.mutation.Where(ps...)
	return abd
}

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

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

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

// AgentBaseDeleteOne is the builder for deleting a single AgentBase entity.
type AgentBaseDeleteOne struct {
	abd *AgentBaseDelete
}

// Where appends a list predicates to the AgentBaseDelete builder.
func (abdo *AgentBaseDeleteOne) Where(ps ...predicate.AgentBase) *AgentBaseDeleteOne {
	abdo.abd.mutation.Where(ps...)
	return abdo
}

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

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