// Code generated by ent, DO NOT EDIT.

package ent

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

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

// ContactFieldTemplateDelete is the builder for deleting a ContactFieldTemplate entity.
type ContactFieldTemplateDelete struct {
	config
	hooks    []Hook
	mutation *ContactFieldTemplateMutation
}

// Where appends a list predicates to the ContactFieldTemplateDelete builder.
func (cftd *ContactFieldTemplateDelete) Where(ps ...predicate.ContactFieldTemplate) *ContactFieldTemplateDelete {
	cftd.mutation.Where(ps...)
	return cftd
}

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

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

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

// ContactFieldTemplateDeleteOne is the builder for deleting a single ContactFieldTemplate entity.
type ContactFieldTemplateDeleteOne struct {
	cftd *ContactFieldTemplateDelete
}

// Where appends a list predicates to the ContactFieldTemplateDelete builder.
func (cftdo *ContactFieldTemplateDeleteOne) Where(ps ...predicate.ContactFieldTemplate) *ContactFieldTemplateDeleteOne {
	cftdo.cftd.mutation.Where(ps...)
	return cftdo
}

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

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