// Generated using `moon info`, DON'T EDIT IT
package "Novanke/swarmcrate"

import {
  "moonbitlang/core/debug",
}

// Values
pub fn assess_staging(Bytes, Bytes?, StagingEvidence) -> StagingAssessment

pub fn audit_batch(BatchManifest, (Int32, BatchTask) -> Bytes raise CrateError, (Int32, TorrentInfo, VerificationScope) -> Array[Int64?] raise CrateError, (Int32, Int32, Int64, Int32) -> Bytes raise CrateError, finish? : ((Int32) -> Unit raise CrateError)?, detail_limit? : Int32, max_summary_bytes? : Int32) -> BatchAudit raise CrateError

pub fn audit_batch_with_control(BatchManifest, (Int32, BatchTask) -> Bytes raise CrateError, (Int32, TorrentInfo, VerificationScope) -> Array[Int64?] raise CrateError, (Int32, Int32, Int64, Int32) -> Bytes raise CrateError, (BatchProgress) -> Bool raise CrateError, finish? : ((Int32) -> Unit raise CrateError)?, detail_limit? : Int32, max_summary_bytes? : Int32) -> BatchAudit raise CrateError

pub fn batch_audit_exit_code(BatchAudit) -> Int32

pub fn batch_audit_json_text(BatchAudit) -> String

pub fn batch_manifest_tasks(BatchManifest) -> Array[BatchTask]

pub fn batch_progress_json(BatchProgress) -> Json

pub fn check_bencode(Bytes) -> Unit raise CrateError

pub fn create_options(String) -> CreateOptions

pub fn create_torrent(Array[SourceFile], CreateOptions, (Int32, Int64, Int32) -> Bytes raise CrateError) -> Bytes raise CrateError

pub fn create_torrent_with_control(Array[SourceFile], CreateOptions, (Int32, Int64, Int32) -> Bytes raise CrateError, (CreationProgress) -> Bool raise CrateError) -> Bytes raise CrateError

pub fn edit_distribution(Bytes, Array[Array[String]], Array[String]) -> Bytes raise CrateError

pub fn expected_v1_pieces(Bytes) -> Bytes raise CrateError

pub fn expected_v2_files(Bytes) -> Array[V2FileHash] raise CrateError

pub fn format_magnet(Magnet) -> String raise CrateError

pub fn hash_v2_file(Int64, Int32, (Int64, Int32) -> Bytes raise CrateError) -> V2FileHash raise CrateError

pub fn info_json(TorrentInfo) -> Json

pub fn inspect_torrent(Bytes) -> TorrentInfo raise CrateError

pub fn mode_name(TorrentMode) -> String

pub fn parse_batch_manifest(Bytes) -> BatchManifest raise CrateError

pub fn parse_magnet(String) -> Magnet raise CrateError

pub fn parse_staging_owner(Bytes) -> StagingOwner raise CrateError

pub fn piece_spans(Array[SourceFile], Int32, Int32) -> Array[PieceSpan] raise CrateError

pub fn plan_json(TorrentPlan) -> Json

pub fn plan_torrent(Array[SourceFile], CreateOptions) -> TorrentPlan raise CrateError

pub fn receipt_diagnostics_json_text(VerificationReceipt) -> String

pub fn receipt_json_text(VerificationReceipt) -> String

pub fn recommend_piece_length(Array[SourceFile], mode? : TorrentMode, target_pieces? : Int32) -> Int32 raise CrateError

pub fn sha1_pieces(Array[SourceFile], Int32, (Int32, Int64, Int32) -> Bytes raise CrateError) -> Bytes raise CrateError

pub fn sorted_source_indices(Array[SourceFile]) -> Array[Int32] raise CrateError

pub fn staging_owner_bytes(StagingOwner) -> Bytes raise CrateError

pub fn torrent_magnet(Bytes) -> String raise CrateError

pub fn torrent_storage_bytes(Bytes) -> Int64 raise CrateError

pub fn valid_staging_operation_id(String) -> Bool

pub fn validate_options(Array[SourceFile], CreateOptions) -> Unit raise CrateError

pub fn validate_piece_layer(Bytes, Int64, Int32, Bytes) -> Unit raise CrateError

pub fn validate_sources(Array[SourceFile]) -> Int64 raise CrateError

pub fn verification_html(TorrentInfo, VerificationReport) -> String

pub fn verification_json(VerificationReport) -> Json

pub fn verification_scope(Bytes, selected_files? : Array[Int32]?) -> VerificationScope raise CrateError

pub fn verify_payload(Bytes, Array[Int64?], (Int32, Int64, Int32) -> Bytes raise CrateError, detail_limit? : Int32, selected_files? : Array[Int32]?) -> VerificationReport raise CrateError

pub fn verify_with_control(Bytes, Array[Int64?], (Int32, Int64, Int32) -> Bytes raise CrateError, (VerificationProgress) -> Bool raise CrateError, detail_limit? : Int32, selected_files? : Array[Int32]?) -> (VerificationReport, VerificationReceipt) raise CrateError

pub fn verify_with_receipt(Bytes, Array[Int64?], (Int32, Int64, Int32) -> Bytes raise CrateError, detail_limit? : Int32, selected_files? : Array[Int32]?) -> (VerificationReport, VerificationReceipt) raise CrateError

// Errors
pub(all) suberror CrateError {
  CrateError(String, String)
} derive(@debug.Debug)
pub fn CrateError::to_repr(Self) -> @debug.Repr

// Types and methods
pub struct BatchAudit {
  // private fields
}

pub struct BatchManifest {
  // private fields
}

pub(all) struct BatchProgress {
  phase : String
  manifest_sha256 : String
  task_count : Int32
  completed_tasks : Int32
  pass_tasks : Int32
  partial_pass_tasks : Int32
  failed_tasks : Int32
  error_tasks : Int32
  read_calls : Int64
  validated_read_bytes : Int64
  task_index : Int32?
  task_id : String?
  task_outcome : String?
  verification : VerificationProgress?
}

pub(all) struct BatchTask {
  id : String
  metainfo : String
  payload : String
  files : Array[String]?
}

pub(all) struct CreateOptions {
  name : String
  mode : TorrentMode
  piece_length : Int32
  single_file : Bool
  private_torrent : Bool
  trackers : Array[Array[String]]
  web_seeds : Array[String]
  comment : String
}

pub(all) struct CreationProgress {
  phase : String
  mode : TorrentMode
  file_count : Int32
  total_bytes : Int64
  read_calls : Int32
  validated_read_bytes : Int64
  file : Int32?
  offset : Int64?
  length : Int32?
  metainfo_bytes : Int32?
}

pub(all) struct FileIssue {
  file : Int32
  path : String
  expected : Int64
  actual : Int64?
  reason : String
}

pub(all) struct Magnet {
  v1 : String?
  v2 : String?
  name : String?
  trackers : Array[String]
}

pub(all) struct PieceFailure {
  scheme : String
  piece : Int32
  spans : Array[PieceSpan]
  reason : String
}

pub(all) struct PieceSpan {
  file : Int32
  offset : Int64
  length : Int32
}

pub(all) struct SourceFile {
  path : Array[String]
  length : Int64
}

pub(all) struct StagingAssessment {
  status : String
  reason : String
  operation_id : String?
}

pub(all) struct StagingEvidence {
  stage_path : String
  directory_id : String
  data_id : String
  actual_bytes : Int64
  local_host : String
  local_user : String
  owner_state : String
}

pub(all) struct StagingOwner {
  operation_id : String
  stage_path : String
  target_path : String
  directory_id : String
  data_id : String
  pid : Int32
  host : String
  user : String
  expected_bytes : Int64
}

pub(all) struct TorrentInfo {
  name : String
  mode : TorrentMode
  piece_length : Int32
  files : Array[SourceFile]
  single_file : Bool
  private_torrent : Bool
  trackers : Array[Array[String]]
  web_seeds : Array[String]
  comment : String
  info_hash_v1 : String?
  info_hash_v2 : String?
}

pub(all) enum TorrentMode {
  V1
  V2
  Hybrid
} derive(Eq, @debug.Debug)
pub fn TorrentMode::equal(Self, Self) -> Bool
pub fn TorrentMode::not_equal(Self, Self) -> Bool
pub fn TorrentMode::to_repr(Self) -> @debug.Repr

pub(all) struct TorrentPlan {
  name : String
  mode : TorrentMode
  piece_length : Int32
  single_file : Bool
  file_count : Int32
  empty_files : Int32
  real_bytes : Int64
  storage_bytes : Int64
  padding_bytes : Int64
  v1_pieces : Int32
  v2_pieces : Int32
  v1_hash_bytes : Int64
  v2_piece_layer_bytes_upper_bound : Int64
}

pub(all) struct V2FileHash {
  root : Bytes
  piece_layer : Bytes
}

pub(all) struct VerificationProgress {
  phase : String
  total_checks : Int32
  checked_pieces : Int32
  failed_pieces : Int32
  unreadable_pieces : Int32
  read_calls : Int32
  validated_read_bytes : Int64
  complete_scope : Bool
  selected_file_count : Int32
  required_file_count : Int32
  file : Int32?
  offset : Int64?
  length : Int32?
  read_ok : Bool?
}

pub struct VerificationReceipt {
  // private fields
}

pub(all) struct VerificationReport {
  ok : Bool
  scope : VerificationScope
  checked_pieces : Int32
  skipped_pieces : Int32
  failed_pieces : Int32
  unreadable_pieces : Int32
  file_issues : Array[FileIssue]
  failures : Array[PieceFailure]
  details_truncated : Bool
}

pub(all) struct VerificationScope {
  complete : Bool
  selected_files : Array[Int32]
  required_files : Array[Int32]
}

// Type aliases

// Traits
