// Code generated by ent, DO NOT EDIT.

package ent

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

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

// UsageStatisticDayDelete is the builder for deleting a UsageStatisticDay entity.
type UsageStatisticDayDelete struct {
	config
	hooks    []Hook
	mutation *UsageStatisticDayMutation
}

// Where appends a list predicates to the UsageStatisticDayDelete builder.
func (usdd *UsageStatisticDayDelete) Where(ps ...predicate.UsageStatisticDay) *UsageStatisticDayDelete {
	usdd.mutation.Where(ps...)
	return usdd
}

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

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

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

// UsageStatisticDayDeleteOne is the builder for deleting a single UsageStatisticDay entity.
type UsageStatisticDayDeleteOne struct {
	usdd *UsageStatisticDayDelete
}

// Where appends a list predicates to the UsageStatisticDayDelete builder.
func (usddo *UsageStatisticDayDeleteOne) Where(ps ...predicate.UsageStatisticDay) *UsageStatisticDayDeleteOne {
	usddo.usdd.mutation.Where(ps...)
	return usddo
}

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

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