/**
 * Transaction builder storing a sequence of deferred operations that assemble and balance a transaction.
 *
 * @module TransactionBuilder
 * @since 2.0.0
 *
 * ## Execution Model
 *
 * The builder pattern:
 * - **Immutable configuration** at construction (protocol params, change address, available UTxOs)
 * - **ProgramSteps array** accumulates deferred effects via chainable API methods
 * - **Fresh state per build()** — each execution creates new Ref instances, runs all programs sequentially
 * - **Deferred composition** — no I/O or state updates occur until build() is invoked
 *
 * Key invariant: calling `build()` twice with the same builder instance produces two independent results
 * with no cross-contamination because fresh state (Refs) is created each time.
 *
 * ## Coin Selection
 *
 * Automatic coin selection selects UTxOs from `availableUtxos` to satisfy transaction outputs and fees.
 * The `collectFrom()` method allows manual input selection; automatic selection excludes these to prevent
 * double-spending. UTxOs can come from any source (wallet, DeFi protocols, other participants, etc.).
 *
 * @since 2.0.0
 */
// Effect-TS imports
import { Context, Data } from "effect";
import * as Bytes from "../../Bytes.js";
import * as BuilderFactory from "./internal/factory.js";
// ============================================================================
// Errors
// ============================================================================
/**
 * Error thrown when transaction building fails.
 *
 * @since 2.0.0
 * @category errors
 */
export class TransactionBuilderError extends /*#__PURE__*/Data.TaggedError("TransactionBuilderError") {}
/**
 * Error thrown when script evaluation fails.
 *
 * @since 2.0.0
 * @category errors
 */
export class EvaluationError extends /*#__PURE__*/Data.TaggedError("EvaluationError") {}
// ============================================================================
// Context Tags
// ============================================================================
/**
 * Context tag providing build-phase state.
 *
 * @since 2.0.0
 * @category context
 */
export class PhaseContextTag extends /*#__PURE__*/Context.Tag("PhaseContextTag")() {}
/**
 * Context tag providing the mutable transaction state.
 *
 * @since 2.0.0
 * @category context
 */
export class TxContext extends /*#__PURE__*/Context.Tag("TxContext")() {}
/**
 * Context tag providing the change address.
 *
 * @since 2.0.0
 * @category context
 */
export class ChangeAddressTag extends /*#__PURE__*/Context.Tag("ChangeAddress")() {}
/**
 * Context tag providing protocol parameters.
 *
 * @since 2.0.0
 * @category context
 */
export class ProtocolParametersTag extends /*#__PURE__*/Context.Tag("ProtocolParameters")() {}
/**
 * Context tag providing the builder configuration.
 *
 * @since 2.0.0
 * @category context
 */
export class TxBuilderConfigTag extends /*#__PURE__*/Context.Tag("TxBuilderConfig")() {}
/**
 * Context tag providing available UTxOs for coin selection.
 *
 * @since 2.0.0
 * @category context
 */
export class AvailableUtxosTag extends /*#__PURE__*/Context.Tag("AvailableUtxos")() {}
/**
 * Context tag providing build options for the current build.
 *
 * @since 2.0.0
 * @category context
 */
export class BuildOptionsTag extends /*#__PURE__*/Context.Tag("BuildOptions")() {}
// ============================================================================
// Voter Key
// ============================================================================
/**
 * Convert a Voter to a unique string key for redeemer tracking.
 *
 * @since 2.0.0
 * @category utilities
 */
export const voterToKey = voter => {
  switch (voter._tag) {
    case "ConstitutionalCommitteeVoter":
      return `cc:${Bytes.toHex(voter.credential.hash)}`;
    case "DRepVoter":
      switch (voter.drep._tag) {
        case "KeyHashDRep":
          return `drep:${Bytes.toHex(voter.drep.keyHash.hash)}`;
        case "ScriptHashDRep":
          return `drep:${Bytes.toHex(voter.drep.scriptHash.hash)}`;
        default:
          return `drep:${voter.drep._tag}`;
      }
    case "StakePoolVoter":
      return `pool:${Bytes.toHex(voter.poolKeyHash.hash)}`;
  }
};
export function makeTxBuilder(config) {
  return BuilderFactory.makeTxBuilder(config);
}
//# sourceMappingURL=TransactionBuilder.js.map