// Code generated by ent, DO NOT EDIT.

package ent

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

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

// UsageDetailDelete is the builder for deleting a UsageDetail entity.
type UsageDetailDelete struct {
	config
	hooks    []Hook
	mutation *UsageDetailMutation
}

// Where appends a list predicates to the UsageDetailDelete builder.
func (udd *UsageDetailDelete) Where(ps ...predicate.UsageDetail) *UsageDetailDelete {
	udd.mutation.Where(ps...)
	return udd
}

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

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

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

// UsageDetailDeleteOne is the builder for deleting a single UsageDetail entity.
type UsageDetailDeleteOne struct {
	udd *UsageDetailDelete
}

// Where appends a list predicates to the UsageDetailDelete builder.
func (uddo *UsageDetailDeleteOne) Where(ps ...predicate.UsageDetail) *UsageDetailDeleteOne {
	uddo.udd.mutation.Where(ps...)
	return uddo
}

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

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