@0xdbbcd8ccbd223b6c; # unique file ID, generated by `capnp id`

struct AssetUuid {
    id @0 :Data;
}

struct AssetRef {
  union {
    uuid @0 :AssetUuid;
    path @1 :Data;
  }
}

struct AssetUuidList {
    list @0 :List(AssetUuid);
}

struct KeyValue {
  key @0 :Data;
  value @1 :Data;
}

enum FileType {
  file @0;
  directory @1;
  symlink @2;
  none @3;
}

enum FileState {
  exists @0;
  deleted @1;
}

enum AssetSource {
  file @0;
}

struct DirtyFileInfo {
  state @0 :FileState;
  sourceInfo @1 :SourceFileInfo;
}

struct SourceFileInfo {
  type @0 :FileType;
  lastModified @1 :UInt64;
  length @2 :UInt64;
}

struct RenameFileEvent {
  src @0 :Data;
  dst @1 :Data;
}

struct AssetUuidPair {
  key @0 :AssetUuid;
  value @1 :AssetUuid;
}

struct SourceMetadata {
  assets @0 :List(AssetMetadata);
  importerVersion @1 :UInt32;
  importerOptionsType @2 :Data;
  importerOptions @3 :Data;
  importerStateType @4 :Data;
  importerState @5 :Data;
  buildPipelines @6 :List(AssetUuidPair);
  importerType @7 :Data;
  union {
    error @8 :Error;
    noError @9 :Void;
  }
  pathRefs @10 :List(Data);
  importHash @11 :Data;
}

struct PathRefs {
  paths @0 :List(Data);
}

struct Error {
  text @0 :Text;
}

struct ArtifactMetadata {
  assetId @0 :AssetUuid;
  hash @1 :Data;
  loadDeps @2 :List(AssetRef);
  buildDeps @3 :List(AssetRef);
  compression @4 :CompressionType;
  compressedSize @5 :UInt64;
  uncompressedSize @6 :UInt64;
  typeId @7 :Data;
}

struct AssetMetadata {
  id @0 :AssetUuid;
  searchTags @1 :List(KeyValue);
  buildPipeline @2 :AssetUuid;
  # The most recently recorded artifact of the import function
  latestArtifact :union {
    artifact @3 :ArtifactMetadata;
    none @4 :Void;
  }
  # The source of the imported asset
  source @5 :AssetSource;
  union {
    error @6 :Error;
    noError @7 :Void;
  }
}

# The identifier for a build artifact is the hash of 
# - Import artifact hash
# - Build parameters (target platform etc)
# - Build pipeline hash

# The identifier of an import artifact is the hash of 
# - Source file
# - Importer version
# - Importer TypeUUID
# - Importer state
# - Importer state TypeUUID
# - Importer options
# - Importer options TypeUUID

struct Artifact {
    metadata @0 :ArtifactMetadata;
    data @1 :Data;  # Serialized data as per metadata
}

struct BuildParameters {

}

struct AssetChangeLogEntry {
  num @0 :UInt64;
  event @1 :AssetChangeEvent;
}
struct AssetChangeEvent {
  union {
    contentUpdateEvent @0 :AssetContentUpdateEvent;
    removeEvent @1 :AssetRemoveEvent;
  }
}

struct AssetContentUpdateEvent {
    id @0 :AssetUuid;
    importHash @1 :Data;
    # `buildDepHash` is the hash of all build dependencies' import hashes sorted by their AssetUUID.
    # It can be used to determine if a build artifact needs to be invalidated
    # by hashing (import_hash, build_dep_hash, build_pipeline_hash, build_parameters)
    buildDepHash @2 :Data;
}

struct AssetRemoveEvent {
    id @0 :AssetUuid;
}

enum CompressionType {
  none @0;
  lz4 @1;
}

struct DaemonInfo {
  version @0 :UInt32;
}