// Code generated by ent, DO NOT EDIT.

package ent

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

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

// LabelLogDelete is the builder for deleting a LabelLog entity.
type LabelLogDelete struct {
	config
	hooks    []Hook
	mutation *LabelLogMutation
}

// Where appends a list predicates to the LabelLogDelete builder.
func (lld *LabelLogDelete) Where(ps ...predicate.LabelLog) *LabelLogDelete {
	lld.mutation.Where(ps...)
	return lld
}

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

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

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

// LabelLogDeleteOne is the builder for deleting a single LabelLog entity.
type LabelLogDeleteOne struct {
	lld *LabelLogDelete
}

// Where appends a list predicates to the LabelLogDelete builder.
func (lldo *LabelLogDeleteOne) Where(ps ...predicate.LabelLog) *LabelLogDeleteOne {
	lldo.lld.mutation.Where(ps...)
	return lldo
}

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

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