// Code generated by ent, DO NOT EDIT.

package ent

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

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

// WhatsappChannelDelete is the builder for deleting a WhatsappChannel entity.
type WhatsappChannelDelete struct {
	config
	hooks    []Hook
	mutation *WhatsappChannelMutation
}

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

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

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

// WhatsappChannelDeleteOne is the builder for deleting a single WhatsappChannel entity.
type WhatsappChannelDeleteOne struct {
	wcd *WhatsappChannelDelete
}

// Where appends a list predicates to the WhatsappChannelDelete builder.
func (wcdo *WhatsappChannelDeleteOne) Where(ps ...predicate.WhatsappChannel) *WhatsappChannelDeleteOne {
	wcdo.wcd.mutation.Where(ps...)
	return wcdo
}

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

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