/*
 * SPDX-FileCopyrightText: © 2017-2025 Istari Digital, Inc.
 * SPDX-License-Identifier: Apache-2.0
 */

package badger

// OpenManaged returns a new DB, which allows more control over setting
// transaction timestamps, aka managed mode.
//
// This is only useful for databases built on top of Badger (like Dgraph), and
// can be ignored by most users.
func ( Options) (*DB, error) {
	.managedTxns = true
	return Open()
}

// NewTransactionAt follows the same logic as DB.NewTransaction(), but uses the
// provided read timestamp.
//
// This is only useful for databases built on top of Badger (like Dgraph), and
// can be ignored by most users.
func ( *DB) ( uint64,  bool) *Txn {
	if !.opt.managedTxns {
		panic("Cannot use NewTransactionAt with managedDB=false. Use NewTransaction instead.")
	}
	 := .newTransaction(, true)
	.readTs = 
	return 
}

// NewWriteBatchAt is similar to NewWriteBatch but it allows user to set the commit timestamp.
// NewWriteBatchAt is supposed to be used only in the managed mode.
func ( *DB) ( uint64) *WriteBatch {
	if !.opt.managedTxns {
		panic("cannot use NewWriteBatchAt with managedDB=false. Use NewWriteBatch instead")
	}

	 := .newWriteBatch(true)
	.commitTs = 
	.txn.commitTs = 
	return 
}
func ( *DB) () *WriteBatch {
	if !.opt.managedTxns {
		panic("cannot use NewManagedWriteBatch with managedDB=false. Use NewWriteBatch instead")
	}

	 := .newWriteBatch(true)
	return 
}

// CommitAt commits the transaction, following the same logic as Commit(), but
// at the given commit timestamp. This will panic if not used with managed transactions.
//
// This is only useful for databases built on top of Badger (like Dgraph), and
// can be ignored by most users.
func ( *Txn) ( uint64,  func(error)) error {
	if !.db.opt.managedTxns {
		panic("Cannot use CommitAt with managedDB=false. Use Commit instead.")
	}
	.commitTs = 
	if  == nil {
		return .Commit()
	}
	.CommitWith()
	return nil
}

// SetDiscardTs sets a timestamp at or below which, any invalid or deleted
// versions can be discarded from the LSM tree, and thence from the value log to
// reclaim disk space. Can only be used with managed transactions.
func ( *DB) ( uint64) {
	if !.opt.managedTxns {
		panic("Cannot use SetDiscardTs with managedDB=false.")
	}
	.orc.setDiscardTs()
}