// Code generated by ent, DO NOT EDIT.

package ent

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

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

// CompapiAsynctaskDelete is the builder for deleting a CompapiAsynctask entity.
type CompapiAsynctaskDelete struct {
	config
	hooks    []Hook
	mutation *CompapiAsynctaskMutation
}

// Where appends a list predicates to the CompapiAsynctaskDelete builder.
func (cad *CompapiAsynctaskDelete) Where(ps ...predicate.CompapiAsynctask) *CompapiAsynctaskDelete {
	cad.mutation.Where(ps...)
	return cad
}

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

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

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

// CompapiAsynctaskDeleteOne is the builder for deleting a single CompapiAsynctask entity.
type CompapiAsynctaskDeleteOne struct {
	cad *CompapiAsynctaskDelete
}

// Where appends a list predicates to the CompapiAsynctaskDelete builder.
func (cado *CompapiAsynctaskDeleteOne) Where(ps ...predicate.CompapiAsynctask) *CompapiAsynctaskDeleteOne {
	cado.cad.mutation.Where(ps...)
	return cado
}

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

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