// Code generated by ent, DO NOT EDIT.

package ent

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

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

// WxCardUserDelete is the builder for deleting a WxCardUser entity.
type WxCardUserDelete struct {
	config
	hooks    []Hook
	mutation *WxCardUserMutation
}

// Where appends a list predicates to the WxCardUserDelete builder.
func (wcud *WxCardUserDelete) Where(ps ...predicate.WxCardUser) *WxCardUserDelete {
	wcud.mutation.Where(ps...)
	return wcud
}

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

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

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

// WxCardUserDeleteOne is the builder for deleting a single WxCardUser entity.
type WxCardUserDeleteOne struct {
	wcud *WxCardUserDelete
}

// Where appends a list predicates to the WxCardUserDelete builder.
func (wcudo *WxCardUserDeleteOne) Where(ps ...predicate.WxCardUser) *WxCardUserDeleteOne {
	wcudo.wcud.mutation.Where(ps...)
	return wcudo
}

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

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