// Code generated by ent, DO NOT EDIT.

package ent

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

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

// UsageTotalDelete is the builder for deleting a UsageTotal entity.
type UsageTotalDelete struct {
	config
	hooks    []Hook
	mutation *UsageTotalMutation
}

// Where appends a list predicates to the UsageTotalDelete builder.
func (utd *UsageTotalDelete) Where(ps ...predicate.UsageTotal) *UsageTotalDelete {
	utd.mutation.Where(ps...)
	return utd
}

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

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

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

// UsageTotalDeleteOne is the builder for deleting a single UsageTotal entity.
type UsageTotalDeleteOne struct {
	utd *UsageTotalDelete
}

// Where appends a list predicates to the UsageTotalDelete builder.
func (utdo *UsageTotalDeleteOne) Where(ps ...predicate.UsageTotal) *UsageTotalDeleteOne {
	utdo.utd.mutation.Where(ps...)
	return utdo
}

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

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