// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"galileo/ent/apitag"
	"galileo/ent/predicate"

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

// ApiTagDelete is the builder for deleting a ApiTag entity.
type ApiTagDelete struct {
	config
	hooks    []Hook
	mutation *ApiTagMutation
}

// Where appends a list predicates to the ApiTagDelete builder.
func (atd *ApiTagDelete) Where(ps ...predicate.ApiTag) *ApiTagDelete {
	atd.mutation.Where(ps...)
	return atd
}

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

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

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

// ApiTagDeleteOne is the builder for deleting a single ApiTag entity.
type ApiTagDeleteOne struct {
	atd *ApiTagDelete
}

// Where appends a list predicates to the ApiTagDelete builder.
func (atdo *ApiTagDeleteOne) Where(ps ...predicate.ApiTag) *ApiTagDeleteOne {
	atdo.atd.mutation.Where(ps...)
	return atdo
}

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

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