// Code generated by ent, DO NOT EDIT.

package ent

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

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

// WxCardDelete is the builder for deleting a WxCard entity.
type WxCardDelete struct {
	config
	hooks    []Hook
	mutation *WxCardMutation
}

// Where appends a list predicates to the WxCardDelete builder.
func (wcd *WxCardDelete) Where(ps ...predicate.WxCard) *WxCardDelete {
	wcd.mutation.Where(ps...)
	return wcd
}

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

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

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

// WxCardDeleteOne is the builder for deleting a single WxCard entity.
type WxCardDeleteOne struct {
	wcd *WxCardDelete
}

// Where appends a list predicates to the WxCardDelete builder.
func (wcdo *WxCardDeleteOne) Where(ps ...predicate.WxCard) *WxCardDeleteOne {
	wcdo.wcd.mutation.Where(ps...)
	return wcdo
}

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

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