// Code generated by ent, DO NOT EDIT.

package ent

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

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

// XunjiDelete is the builder for deleting a Xunji entity.
type XunjiDelete struct {
	config
	hooks    []Hook
	mutation *XunjiMutation
}

// Where appends a list predicates to the XunjiDelete builder.
func (xd *XunjiDelete) Where(ps ...predicate.Xunji) *XunjiDelete {
	xd.mutation.Where(ps...)
	return xd
}

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

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

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

// XunjiDeleteOne is the builder for deleting a single Xunji entity.
type XunjiDeleteOne struct {
	xd *XunjiDelete
}

// Where appends a list predicates to the XunjiDelete builder.
func (xdo *XunjiDeleteOne) Where(ps ...predicate.Xunji) *XunjiDeleteOne {
	xdo.xd.mutation.Where(ps...)
	return xdo
}

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

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