// Code generated by ent, DO NOT EDIT.

package ent

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

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

// PayRechargeDelete is the builder for deleting a PayRecharge entity.
type PayRechargeDelete struct {
	config
	hooks    []Hook
	mutation *PayRechargeMutation
}

// Where appends a list predicates to the PayRechargeDelete builder.
func (prd *PayRechargeDelete) Where(ps ...predicate.PayRecharge) *PayRechargeDelete {
	prd.mutation.Where(ps...)
	return prd
}

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

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

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

// PayRechargeDeleteOne is the builder for deleting a single PayRecharge entity.
type PayRechargeDeleteOne struct {
	prd *PayRechargeDelete
}

// Where appends a list predicates to the PayRechargeDelete builder.
func (prdo *PayRechargeDeleteOne) Where(ps ...predicate.PayRecharge) *PayRechargeDeleteOne {
	prdo.prd.mutation.Where(ps...)
	return prdo
}

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

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