// Code generated by ent, DO NOT EDIT.

package ent

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

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

// UsageStatisticMonthDelete is the builder for deleting a UsageStatisticMonth entity.
type UsageStatisticMonthDelete struct {
	config
	hooks    []Hook
	mutation *UsageStatisticMonthMutation
}

// Where appends a list predicates to the UsageStatisticMonthDelete builder.
func (usmd *UsageStatisticMonthDelete) Where(ps ...predicate.UsageStatisticMonth) *UsageStatisticMonthDelete {
	usmd.mutation.Where(ps...)
	return usmd
}

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

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

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

// UsageStatisticMonthDeleteOne is the builder for deleting a single UsageStatisticMonth entity.
type UsageStatisticMonthDeleteOne struct {
	usmd *UsageStatisticMonthDelete
}

// Where appends a list predicates to the UsageStatisticMonthDelete builder.
func (usmdo *UsageStatisticMonthDeleteOne) Where(ps ...predicate.UsageStatisticMonth) *UsageStatisticMonthDeleteOne {
	usmdo.usmd.mutation.Where(ps...)
	return usmdo
}

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

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