// Code generated by ent, DO NOT EDIT.

package ent

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

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

// WpChatroomMemberDelete is the builder for deleting a WpChatroomMember entity.
type WpChatroomMemberDelete struct {
	config
	hooks    []Hook
	mutation *WpChatroomMemberMutation
}

// Where appends a list predicates to the WpChatroomMemberDelete builder.
func (wcmd *WpChatroomMemberDelete) Where(ps ...predicate.WpChatroomMember) *WpChatroomMemberDelete {
	wcmd.mutation.Where(ps...)
	return wcmd
}

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

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

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

// WpChatroomMemberDeleteOne is the builder for deleting a single WpChatroomMember entity.
type WpChatroomMemberDeleteOne struct {
	wcmd *WpChatroomMemberDelete
}

// Where appends a list predicates to the WpChatroomMemberDelete builder.
func (wcmdo *WpChatroomMemberDeleteOne) Where(ps ...predicate.WpChatroomMember) *WpChatroomMemberDeleteOne {
	wcmdo.wcmd.mutation.Where(ps...)
	return wcmdo
}

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

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