// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
	"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/loginrecord"
	"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/predicate"
)

// LoginRecordDelete is the builder for deleting a LoginRecord entity.
type LoginRecordDelete struct {
	config
	hooks    []Hook
	mutation *LoginRecordMutation
}

// Where appends a list predicates to the LoginRecordDelete builder.
func (lrd *LoginRecordDelete) Where(ps ...predicate.LoginRecord) *LoginRecordDelete {
	lrd.mutation.Where(ps...)
	return lrd
}

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

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

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

// LoginRecordDeleteOne is the builder for deleting a single LoginRecord entity.
type LoginRecordDeleteOne struct {
	lrd *LoginRecordDelete
}

// Where appends a list predicates to the LoginRecordDelete builder.
func (lrdo *LoginRecordDeleteOne) Where(ps ...predicate.LoginRecord) *LoginRecordDeleteOne {
	lrdo.lrd.mutation.Where(ps...)
	return lrdo
}

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

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