syntax = "proto3";

package golem.rib;

import "golem/rib/expr.proto";
import "wasm/ast/type.proto";

message FunctionDictionary {
  repeated FunctionEntry map = 1;
}

message FunctionEntry {
  FunctionNameType key = 1;
  FunctionType value = 2;
}

message ResourceMethodDictionary {
  repeated ResourceMethodEntry map = 1;
}

message ResourceMethodEntry {
  FullyQualifiedResourceMethod key = 1;
  FunctionType value = 2;
}

message InstanceType {
  oneof instance {
    GlobalInstance global = 1;
    PackageInstance package = 2;
    InterfaceInstance interface = 3;
    PackageInterfaceInstance package_interface = 4;
    ResourceInstance resource = 5;
  }
}

message GlobalInstance {
  golem.rib.Expr worker_name = 1;
  FunctionDictionary functions_global = 2;
}

message PackageInstance {
  golem.rib.Expr worker_name = 1;
  golem.rib.PackageName package_name = 2;
  FunctionDictionary functions_in_package = 3;
}

message InterfaceInstance {
  golem.rib.Expr worker_name = 1;
  golem.rib.InterfaceName interface_name = 2;
  FunctionDictionary functions_in_interface = 3;
}

message PackageInterfaceInstance {
  golem.rib.Expr worker_name = 1;
  golem.rib.PackageName package_name = 2;
  golem.rib.InterfaceName interface_name = 3;
  FunctionDictionary functions_in_package_interface = 4;
}

message ResourceInstance {
  golem.rib.Expr worker_name = 1;
  optional golem.rib.PackageName package_name = 2;
  optional golem.rib.InterfaceName interface_name = 3;
  string resource_constructor = 4;
  repeated golem.rib.Expr resource_args = 5;
  ResourceMethodDictionary resource_method_dict = 6;
}

// Function-related messages
message FunctionNameType {
  oneof function_name {
    string variant_name = 1;
    string enum_name = 2;
    FullyQualifiedFunctionName function = 3;
    FullyQualifiedResourceConstructor resource_constructor = 4;
    FullyQualifiedResourceMethod resource_method = 5;
  }
}

message FullyQualifiedFunctionName {
  optional golem.rib.PackageName package_name = 1;
  optional golem.rib.InterfaceName interface_name = 2;
  string function_name = 3;
}

message FullyQualifiedResourceMethod {
  optional golem.rib.PackageName package_name = 1;
  optional golem.rib.InterfaceName interface_name = 2;
  string resource_name = 3;
  string method_name = 4;
}

message FunctionType {
  repeated wasm.ast.Type parameter_types = 1;
  optional wasm.ast.Type return_type = 2;
}
