package pool

import (
	
	
)

// SingleConnPool is a pool that always returns the same connection.
// Note: This pool is not thread-safe.
// It is intended to be used by clients that need a single connection.
type SingleConnPool struct {
	pool      Pooler
	cn        *Conn
	stickyErr error
}

var _ Pooler = (*SingleConnPool)(nil)

// NewSingleConnPool creates a new single connection pool.
// The pool will always return the same connection.
// The pool will not:
// - Close the connection
// - Reconnect the connection
// - Track the connection in any way
func ( Pooler,  *Conn) *SingleConnPool {
	return &SingleConnPool{
		pool: ,
		cn:   ,
	}
}

func ( *SingleConnPool) ( context.Context) (*Conn, error) {
	return .pool.NewConn()
}

func ( *SingleConnPool) ( context.Context,  *Conn,  string,  string) error {
	return .pool.CloseConn(, , , )
}

func ( *SingleConnPool) ( context.Context) (*Conn, error) {
	if .stickyErr != nil {
		return nil, .stickyErr
	}
	if .cn == nil {
		return nil, ErrClosed
	}

	// NOTE: SingleConnPool is NOT thread-safe by design and is used in special scenarios:
	// - During initialization (connection is in INITIALIZING state)
	// - During re-authentication (connection is in UNUSABLE state)
	// - For transactions (connection might be in various states)
	// We use SetUsed() which forces the transition, rather than TryTransition() which
	// would fail if the connection is not in IDLE/CREATED state.
	.cn.SetUsed(true)
	.cn.SetUsedAt(time.Now())
	return .cn, nil
}

func ( *SingleConnPool) ( context.Context,  *Conn) {
	if .cn == nil {
		return
	}
	if .cn !=  {
		return
	}
	.cn.SetUsed(false)
}

func ( *SingleConnPool) ( context.Context,  *Conn,  error) {
	.SetUsed(false)
	.cn = nil
	.stickyErr = 
}

// RemoveWithoutTurn has the same behavior as Remove for SingleConnPool
// since SingleConnPool doesn't use a turn-based queue system.
func ( *SingleConnPool) ( context.Context,  *Conn,  error) {
	.Remove(, , )
}

func ( *SingleConnPool) () error {
	.cn = nil
	.stickyErr = ErrClosed
	return nil
}

func ( *SingleConnPool) () int {
	return 0
}

func ( *SingleConnPool) () int {
	return 0
}

// Size returns the maximum pool size, which is always 1 for SingleConnPool.
func ( *SingleConnPool) () int { return 1 }

func ( *SingleConnPool) () *Stats {
	return &Stats{}
}

func ( *SingleConnPool) ( PoolHook) {}

func ( *SingleConnPool) ( PoolHook) {}