// Code generated by ent, DO NOT EDIT.

package ent

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

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

// SopStageDelete is the builder for deleting a SopStage entity.
type SopStageDelete struct {
	config
	hooks    []Hook
	mutation *SopStageMutation
}

// Where appends a list predicates to the SopStageDelete builder.
func (ssd *SopStageDelete) Where(ps ...predicate.SopStage) *SopStageDelete {
	ssd.mutation.Where(ps...)
	return ssd
}

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

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

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

// SopStageDeleteOne is the builder for deleting a single SopStage entity.
type SopStageDeleteOne struct {
	ssd *SopStageDelete
}

// Where appends a list predicates to the SopStageDelete builder.
func (ssdo *SopStageDeleteOne) Where(ps ...predicate.SopStage) *SopStageDeleteOne {
	ssdo.ssd.mutation.Where(ps...)
	return ssdo
}

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

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