// Code generated by ent, DO NOT EDIT.

package ent

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

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

// EmployeeConfigDelete is the builder for deleting a EmployeeConfig entity.
type EmployeeConfigDelete struct {
	config
	hooks    []Hook
	mutation *EmployeeConfigMutation
}

// Where appends a list predicates to the EmployeeConfigDelete builder.
func (ecd *EmployeeConfigDelete) Where(ps ...predicate.EmployeeConfig) *EmployeeConfigDelete {
	ecd.mutation.Where(ps...)
	return ecd
}

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

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

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

// EmployeeConfigDeleteOne is the builder for deleting a single EmployeeConfig entity.
type EmployeeConfigDeleteOne struct {
	ecd *EmployeeConfigDelete
}

// Where appends a list predicates to the EmployeeConfigDelete builder.
func (ecdo *EmployeeConfigDeleteOne) Where(ps ...predicate.EmployeeConfig) *EmployeeConfigDeleteOne {
	ecdo.ecd.mutation.Where(ps...)
	return ecdo
}

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

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