// Code generated by ent, DO NOT EDIT.

package ent

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

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

// ContactFieldDelete is the builder for deleting a ContactField entity.
type ContactFieldDelete struct {
	config
	hooks    []Hook
	mutation *ContactFieldMutation
}

// Where appends a list predicates to the ContactFieldDelete builder.
func (cfd *ContactFieldDelete) Where(ps ...predicate.ContactField) *ContactFieldDelete {
	cfd.mutation.Where(ps...)
	return cfd
}

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

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

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

// ContactFieldDeleteOne is the builder for deleting a single ContactField entity.
type ContactFieldDeleteOne struct {
	cfd *ContactFieldDelete
}

// Where appends a list predicates to the ContactFieldDelete builder.
func (cfdo *ContactFieldDeleteOne) Where(ps ...predicate.ContactField) *ContactFieldDeleteOne {
	cfdo.cfd.mutation.Where(ps...)
	return cfdo
}

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

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