/* tslint:disable */
/* eslint-disable */

/* auto-generated by NAPI-RS */

/**
 * Initialize the Rust logger to output to stderr.
 *
 * @param level - Log level: "trace", "debug", "info", "warn", or "error"
 *
 * @example
 * ```typescript
 * import { initLogging } from '@archildata/client';
 * initLogging('debug'); // Call once at startup
 * ```
 */
export declare function initLogging(level?: string | undefined | null): void
/** Unix user context for permission checks */
export interface UnixUser {
  uid: number
  gid: number
}
/** Inode type enum exposed to JavaScript */
export const enum JsInodeType {
  File = 'File',
  Directory = 'Directory',
  Symlink = 'Symlink',
  BlockDevice = 'BlockDevice',
  CharacterDevice = 'CharacterDevice',
  Fifo = 'Fifo',
  Socket = 'Socket'
}
/**
 * Inode attributes exposed to JavaScript
 *
 * Note: inode_id, size, and rdev use i64 which will be converted to/from
 * JavaScript BigInt automatically by napi-rs when values exceed Number.MAX_SAFE_INTEGER.
 */
export interface InodeAttributes {
  /** Inode ID (use BigInt in JS for values > 2^53) */
  inodeId: number
  /** Type of the inode (File, Directory, Symlink, etc.) */
  inodeType: string
  /** File size in bytes */
  size: number
  /** Owner user ID */
  uid: number
  /** Owner group ID */
  gid: number
  /** Unix permission mode */
  mode: number
  /** Number of hard links */
  nlink: number
  /** Change time (milliseconds since epoch) */
  ctimeMs: number
  /** Access time (milliseconds since epoch) */
  atimeMs: number
  /** Modification time (milliseconds since epoch) */
  mtimeMs: number
  /** Birth/creation time (milliseconds since epoch) */
  btimeMs: number
  /** Device ID for block/char devices */
  rdev?: number
  /** Symlink target if this is a symlink */
  symlinkTarget?: string
}
/** Directory entry returned from readdir */
export interface DirectoryEntry {
  /** Name of the entry */
  name: string
  /** Inode ID of the entry */
  inodeId: number
  /** Type of the entry (File, Directory, etc.) */
  inodeType: string
}
/** Lookup response containing inode info */
export interface LookupResponse {
  /** Inode ID of the found entry (-1 if not found) */
  inodeId: number
  /** Attributes of the found inode */
  attributes: InodeAttributes
}
/** Connection configuration for direct server connections */
export interface DirectConnectionConfig {
  /** Server address (e.g., "localhost:8080") */
  serverAddress: string
  /** File system ID (optional, will be determined by server if not provided) */
  fileSystemId?: number
  /** Log level for Rust logging (e.g., "debug", "info", "warn", "error", "trace") */
  logLevel?: string
}
/** Connection configuration for authenticated connections via mount server */
export interface AuthenticatedConnectionConfig {
  /** Mount server address */
  mountServer: string
  /** Disk name (e.g., "dsk-xxx" or "account/diskname") */
  mountName: string
  /** Optional auth token (uses IAM if not provided) */
  authToken?: string
  /** Optional STS region for IAM authentication */
  stsRegion?: string
}
/**
 * Simplified connection configuration using just region and disk name.
 *
 * This mirrors the CLI's `archil mount` command interface.
 *
 * Example usage:
 * ```javascript
 * const client = await ArchilClient.connect({
 *   region: 'aws-us-east-1',
 *   diskName: 'myaccount/mydisk'
 * });
 * ```
 *
 * To enable debug logging:
 * ```javascript
 * const client = await ArchilClient.connect({
 *   region: 'aws-us-east-1',
 *   diskName: 'myaccount/mydisk',
 *   logLevel: 'debug'  // Enables Rust debug logs to stderr
 * });
 * ```
 */
export interface SimpleConnectionConfig {
  /** Region identifier (e.g., "aws-us-east-1", "gcp-us-central1") */
  region: string
  /** Disk name - either "account/diskname" format or "dsk-xxx" disk ID */
  diskName: string
  /** Optional auth token (uses IAM if not provided) */
  authToken?: string
  /** Optional STS region for IAM authentication (defaults to region from the region parameter) */
  stsRegion?: string
  /** Log level for Rust logging (e.g., "debug", "info", "warn", "error", "trace") */
  logLevel?: string
}
/** Inode ID range returned from reserve_inodes */
export interface InodeRange {
  /** Start of the reserved range (inclusive) */
  start: number
  /** End of the reserved range (exclusive) */
  end: number
}
/** Delegation information for an inode */
export interface DelegationInfo {
  /** Inode ID that the delegation is for */
  inodeId: number
  /** State of the delegation: "Active", "Pending", or "Removing" */
  state: string
}
/** Options for checkout operation */
export interface CheckoutOptions {
  /** Force revoke existing delegations held by other clients (default: false) */
  force?: boolean
}
/**
 * Options for setattr operation
 *
 * All fields are optional - only provided fields will be updated.
 * For atime/mtime: use timestamp in milliseconds, or -1 to set to current time.
 */
export interface SetAttrOptions {
  /** New permission mode (e.g., 0o644) */
  mode?: number
  /** New owner user ID */
  uid?: number
  /** New owner group ID */
  gid?: number
  /** New file size (for truncate) */
  size?: number
  /** New access time in milliseconds since epoch (-1 for current time) */
  atimeMs?: number
  /** New modification time in milliseconds since epoch (-1 for current time) */
  mtimeMs?: number
  /** New change time in milliseconds since epoch */
  ctimeMs?: number
}
/**
 * ArchilClient provides low-level access to Archil filesystem operations.
 *
 * This client uses the headless client mode from archil-client-core to provide
 * direct protocol access without FUSE mount infrastructure.
 */
export declare class ArchilClient {
  /**
   * Connect to an Archil server using a simplified configuration.
   *
   * This is the recommended way to connect and mirrors the CLI interface.
   *
   * @example
   * ```typescript
   * const client = await ArchilClient.connect({
   *   region: 'aws-us-east-1',
   *   diskName: 'myaccount/mydisk'
   * });
   * ```
   */
  static connect(config: SimpleConnectionConfig): Promise<ArchilClient>
  /**
   * Connect to an Archil server using direct connection.
   *
   * This is primarily for testing or internal use.
   */
  static connectDirect(config: DirectConnectionConfig): Promise<ArchilClient>
  /**
   * Close the client connection and release resources.
   *
   * This will sync all pending writes and release all delegations held by
   * this client before closing. Returns the number of delegations that were released.
   */
  close(): Promise<number>
  /** Get attributes for an inode (uses cache). */
  getAttributes(inodeId: number, user?: UnixUser | undefined | null): Promise<InodeAttributes>
  /** Lookup an entry by name in a directory (uses cache). */
  lookupInode(parentInodeId: number, name: string, user?: UnixUser | undefined | null): Promise<LookupResponse>
  /**
   * Read directory entries.
   *
   * Uses the cache layer via snapshot_and_synchronize_directory to ensure
   * the dirent cache is properly populated. This ensures that subsequent
   * lookup_inode calls can find the entries returned here.
   */
  readDirectory(inodeId: number, offset?: number | undefined | null, cookie?: number | undefined | null, user?: UnixUser | undefined | null): Promise<Array<DirectoryEntry>>
  /** Get an extended attribute value. */
  getExtendedAttribute(inodeId: number, name: string, user?: UnixUser | undefined | null): Promise<Buffer | null>
  /** List all extended attribute names. */
  listExtendedAttributes(inodeId: number, user?: UnixUser | undefined | null): Promise<Array<string>>
  /**
   * Read data from a file (uses cache).
   *
   * Returns zero-copy Buffer when possible for optimal performance.
   */
  readInode(inodeId: number, offset: number, length: number, user?: UnixUser | undefined | null): Promise<Buffer>
  /**
   * Checkout (acquire delegation for) an inode for writing.
   *
   * This tracks the delegation locally so that subsequent write operations
   * can proceed without additional server round-trips for permission checks.
   *
   * @example
   * ```typescript
   * // Basic checkout
   * await client.checkout(inodeId);
   *
   * // Force revoke existing delegations from other clients
   * await client.checkout(inodeId, { force: true });
   *
   * // With user context
   * await client.checkout(inodeId, { force: false }, { uid: 1000, gid: 1000 });
   * ```
   */
  checkout(inodeId: number, options?: CheckoutOptions | undefined | null, user?: UnixUser | undefined | null): Promise<void>
  /**
   * Checkin (release delegation for) an inode.
   *
   * This syncs any pending writes and releases the local delegation tracking.
   */
  checkin(inodeId: number, user?: UnixUser | undefined | null): Promise<void>
  /** Release all delegations held by this client. */
  checkinAll(): Promise<number>
  /**
   * Sync all pending writes to the server.
   *
   * This flushes all buffered writes through the transaction scheduler,
   * ensuring data durability before the method returns.
   */
  sync(): Promise<void>
  /**
   * Write data to a file.
   *
   * This performs a proper write operation using the transaction scheduler
   * to batch and commit changes. Requires a delegation on the file
   * (call checkout first).
   *
   * @example
   * ```typescript
   * // First checkout to get write delegation
   * await client.checkout(inodeId);
   * // Then write data
   * await client.writeData(inodeId, 0, Buffer.from('Hello World'), user);
   * // Optionally checkin when done
   * await client.checkin(inodeId);
   * ```
   */
  writeData(inodeId: number, offset: number, data: Buffer, user?: UnixUser | undefined | null): Promise<void>
  /**
   * Set attributes on an inode.
   *
   * Updates file metadata like mode, timestamps, size, etc.
   * Requires a delegation on the inode (call checkout first).
   *
   * For atime_ms and mtime_ms, use -1 to set to current time.
   *
   * @example
   * ```typescript
   * // First checkout to get write delegation
   * await client.checkout(inodeId);
   * // Update timestamps (touch)
   * await client.setattr(inodeId, { atimeMs: -1, mtimeMs: -1 }, user);
   * // Or change mode
   * await client.setattr(inodeId, { mode: 0o755 }, user);
   * // Checkin when done
   * await client.checkin(inodeId);
   * ```
   */
  setattr(inodeId: number, options: SetAttrOptions, user: UnixUser): Promise<InodeAttributes>
  /**
   * Unlink (delete) a file or empty directory.
   *
   * Removes the directory entry from the parent directory. Requires
   * write permission on the parent directory.
   */
  unlink(parentInodeId: number, name: string, user?: UnixUser | undefined | null): Promise<void>
  /**
   * Rename (move) a file or directory.
   *
   * Atomically moves an entry from one location to another. If the destination
   * exists, it will be replaced. Requires write permission on both parent directories.
   *
   * @example
   * ```typescript
   * // Move a file
   * await client.rename(srcParentInodeId, 'oldname.txt', destParentInodeId, 'newname.txt', user);
   * ```
   */
  rename(parentInodeId: number, name: string, newParentInodeId: number, newName: string, user?: UnixUser | undefined | null): Promise<void>
  /**
   * Create a new file or directory.
   *
   * Automatically chooses between unconditional create (if we have a delegation
   * on the parent) and conditional create (if we need the server to issue a delegation).
   *
   * Returns the inode ID of the created file.
   */
  create(parentInodeId: number, name: string, attributes: InodeAttributes, user?: UnixUser | undefined | null): Promise<number>
  /** Mark an inode subtree as immutable. */
  setImmutable(inodeId: number): Promise<void>
  /** Mark an inode subtree as mutable (reverse of set_immutable). */
  setMutable(inodeId: number): Promise<void>
  /** List all immutable subtree root inodes. */
  listImmutableSubtrees(): Promise<Array<number>>
  /**
   * List all delegations currently held by this client.
   *
   * Returns a list of delegation info objects containing the inode ID and state.
   * State is one of: "Active", "Pending", "Removing"
   */
  listDelegations(): Array<DelegationInfo>
}
