// Code generated by ent, DO NOT EDIT.

package ent

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

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

// ApiHistoryDelete is the builder for deleting a ApiHistory entity.
type ApiHistoryDelete struct {
	config
	hooks    []Hook
	mutation *ApiHistoryMutation
}

// Where appends a list predicates to the ApiHistoryDelete builder.
func (ahd *ApiHistoryDelete) Where(ps ...predicate.ApiHistory) *ApiHistoryDelete {
	ahd.mutation.Where(ps...)
	return ahd
}

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

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

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

// ApiHistoryDeleteOne is the builder for deleting a single ApiHistory entity.
type ApiHistoryDeleteOne struct {
	ahd *ApiHistoryDelete
}

// Where appends a list predicates to the ApiHistoryDelete builder.
func (ahdo *ApiHistoryDeleteOne) Where(ps ...predicate.ApiHistory) *ApiHistoryDeleteOne {
	ahdo.ahd.mutation.Where(ps...)
	return ahdo
}

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

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