// Code generated by ent, DO NOT EDIT.

package ent

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

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

// ChatSessionDelete is the builder for deleting a ChatSession entity.
type ChatSessionDelete struct {
	config
	hooks    []Hook
	mutation *ChatSessionMutation
}

// Where appends a list predicates to the ChatSessionDelete builder.
func (csd *ChatSessionDelete) Where(ps ...predicate.ChatSession) *ChatSessionDelete {
	csd.mutation.Where(ps...)
	return csd
}

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

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

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

// ChatSessionDeleteOne is the builder for deleting a single ChatSession entity.
type ChatSessionDeleteOne struct {
	csd *ChatSessionDelete
}

// Where appends a list predicates to the ChatSessionDelete builder.
func (csdo *ChatSessionDeleteOne) Where(ps ...predicate.ChatSession) *ChatSessionDeleteOne {
	csdo.csd.mutation.Where(ps...)
	return csdo
}

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

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