// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"registry-backend/ent/personalaccesstoken"
	"registry-backend/ent/predicate"

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

// PersonalAccessTokenDelete is the builder for deleting a PersonalAccessToken entity.
type PersonalAccessTokenDelete struct {
	config
	hooks    []Hook
	mutation *PersonalAccessTokenMutation
}

// Where appends a list predicates to the PersonalAccessTokenDelete builder.
func (patd *PersonalAccessTokenDelete) Where(ps ...predicate.PersonalAccessToken) *PersonalAccessTokenDelete {
	patd.mutation.Where(ps...)
	return patd
}

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

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

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

// PersonalAccessTokenDeleteOne is the builder for deleting a single PersonalAccessToken entity.
type PersonalAccessTokenDeleteOne struct {
	patd *PersonalAccessTokenDelete
}

// Where appends a list predicates to the PersonalAccessTokenDelete builder.
func (patdo *PersonalAccessTokenDeleteOne) Where(ps ...predicate.PersonalAccessToken) *PersonalAccessTokenDeleteOne {
	patdo.patd.mutation.Where(ps...)
	return patdo
}

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

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