// Code generated by ent, DO NOT EDIT.

package ent

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

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

// WpChatroomDelete is the builder for deleting a WpChatroom entity.
type WpChatroomDelete struct {
	config
	hooks    []Hook
	mutation *WpChatroomMutation
}

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

// Exec executes the deletion query and returns how many vertices were deleted.
func (wcd *WpChatroomDelete) 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 *WpChatroomDelete) ExecX(ctx context.Context) int {
	n, err := wcd.Exec(ctx)
	if err != nil {
		panic(err)
	}
	return n
}

func (wcd *WpChatroomDelete) sqlExec(ctx context.Context) (int, error) {
	_spec := sqlgraph.NewDeleteSpec(wpchatroom.Table, sqlgraph.NewFieldSpec(wpchatroom.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
}

// WpChatroomDeleteOne is the builder for deleting a single WpChatroom entity.
type WpChatroomDeleteOne struct {
	wcd *WpChatroomDelete
}

// Where appends a list predicates to the WpChatroomDelete builder.
func (wcdo *WpChatroomDeleteOne) Where(ps ...predicate.WpChatroom) *WpChatroomDeleteOne {
	wcdo.wcd.mutation.Where(ps...)
	return wcdo
}

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

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