// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"formulago/data/ent/menu"
	"formulago/data/ent/predicate"

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

// MenuDelete is the builder for deleting a Menu entity.
type MenuDelete struct {
	config
	hooks    []Hook
	mutation *MenuMutation
}

// Where appends a list predicates to the MenuDelete builder.
func (md *MenuDelete) Where(ps ...predicate.Menu) *MenuDelete {
	md.mutation.Where(ps...)
	return md
}

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

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

func (md *MenuDelete) sqlExec(ctx context.Context) (int, error) {
	_spec := &sqlgraph.DeleteSpec{
		Node: &sqlgraph.NodeSpec{
			Table: menu.Table,
			ID: &sqlgraph.FieldSpec{
				Type:   field.TypeUint64,
				Column: menu.FieldID,
			},
		},
	}
	if ps := md.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	affected, err := sqlgraph.DeleteNodes(ctx, md.driver, _spec)
	if err != nil && sqlgraph.IsConstraintError(err) {
		err = &ConstraintError{msg: err.Error(), wrap: err}
	}
	md.mutation.done = true
	return affected, err
}

// MenuDeleteOne is the builder for deleting a single Menu entity.
type MenuDeleteOne struct {
	md *MenuDelete
}

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

// ExecX is like Exec, but panics if an error occurs.
func (mdo *MenuDeleteOne) ExecX(ctx context.Context) {
	mdo.md.ExecX(ctx)
}
