import "steammessages_unified_base.steamworkssdk.proto";

enum ESteamLearnDataType {
	STEAMLEARN_DATATYPE_INVALID = 0;
	STEAMLEARN_DATATYPE_INT32 = 1;
	STEAMLEARN_DATATYPE_FLOAT32 = 2;
	STEAMLEARN_DATATYPE_BOOL = 3;
	STEAMLEARN_DATATYPE_STRING = 4;
	STEAMLEARN_DATATYPE_OBJECT = 5;
}

enum ESteammLearnRegisterDataSourceResult {
	STEAMLEARN_REGISTER_DATA_SOURCE_RESULT_ERROR = 0;
	STEAMLEARN_REGISTER_DATA_SOURCE_RESULT_SUCCESS_CREATED = 1;
	STEAMLEARN_REGISTER_DATA_SOURCE_RESULT_SUCCESS_FOUND = 2;
	STEAMLEARN_REGISTER_DATA_SOURCE_RESULT_ERROR_GENERIC = 3;
	STEAMLEARN_REGISTER_DATA_SOURCE_RESULT_ERROR_INVALID_NAME = 4;
	STEAMLEARN_REGISTER_DATA_SOURCE_RESULT_ERROR_INVALID_VERSION = 5;
	STEAMLEARN_REGISTER_DATA_SOURCE_RESULT_ERROR_DATA_CHANGED = 6;
	STEAMLEARN_REGISTER_DATA_SOURCE_RESULT_ERROR_DATA_INVALID = 7;
	STEAMLEARN_REGISTER_DATA_SOURCE_RESULT_ERROR_FORBIDDEN = 8;
	STEAMLEARN_REGISTER_DATA_SOURCE_RESULT_ERROR_INVALID_TIMESTAMP = 9;
	STEAMLEARN_REGISTER_DATA_SOURCE_RESULT_DISABLED = 10;
}

enum ESteamLearnCacheDataResult {
	STEAMLEARN_CACHE_DATA_ERROR = 0;
	STEAMLEARN_CACHE_DATA_SUCCESS = 1;
	STEAMLEARN_CACHE_DATA_ERROR_UNKNOWN_DATA_SOURCE = 2;
	STEAMLEARN_CACHE_DATA_ERROR_UNCACHED_DATA_SOURCE = 3;
	STEAMLEARN_CACHE_DATA_ERROR_INVALID_KEYS = 4;
	STEAMLEARN_CACHE_DATA_ERROR_FORBIDDEN = 5;
	STEAMLEARN_CACHE_DATA_ERROR_INVALID_TIMESTAMP = 6;
	STEAMLEARN_CACHE_DATA_DISABLED = 7;
}

enum ESteamLearnSnapshotProjectResult {
	STEAMLEARN_SNAPSHOT_PROJECT_ERROR = 0;
	STEAMLEARN_SNAPSHOT_PROJECT_SUCCESS_STORED = 1;
	STEAMLEARN_SNAPSHOT_PROJECT_SUCCESS_QUEUED = 2;
	STEAMLEARN_SNAPSHOT_PROJECT_ERROR_INVALID_PROJECT_ID = 3;
	STEAMLEARN_SNAPSHOT_PROJECT_ERROR_UNKNOWN_DATA_SOURCE = 4;
	STEAMLEARN_SNAPSHOT_PROJECT_ERROR_INVALID_DATA_SOURCE_KEY = 5;
	STEAMLEARN_SNAPSHOT_PROJECT_ERROR_MISSING_CACHE_DURATION = 6;
	STEAMLEARN_SNAPSHOT_PROJECT_ERROR_NO_PUBLISHED_CONFIG = 7;
	STEAMLEARN_SNAPSHOT_PROJECT_ERROR_FORBIDDEN = 8;
	STEAMLEARN_SNAPSHOT_PROJECT_ERROR_INVALID_TIMESTAMP = 9;
	STEAMLEARN_SNAPSHOT_PROJECT_ERROR_INTERNAL_DATA_SOURCE_ERROR = 10;
	STEAMLEARN_SNAPSHOT_PROJECT_DISABLED = 11;
	STEAMLEARN_SNAPSHOT_PROJECT_ERROR_INVALID_PUBLISHED_VERSION = 12;
}

enum ESteamLearnGetAccessTokensResult {
	STEAMLEARN_GET_ACCESS_TOKENS_ERROR = 0;
	STEAMLEARN_GET_ACCESS_TOKENS_SUCCESS = 1;
}

enum ESteamLearnInferenceResult {
	STEAMLEARN_INFERENCE_ERROR = 0;
	STEAMLEARN_INFERENCE_SUCCESS = 1;
	STEAMLEARN_INFERENCE_ERROR_INVALID_PROJECT_ID = 2;
	STEAMLEARN_INFERENCE_ERROR_MISSING_CACHED_SCHEMA_DATA = 3;
	STEAMLEARN_INFERENCE_ERROR_NO_PUBLISHED_CONFIG = 4;
	STEAMLEARN_INFERENCE_ERROR_FORBIDDEN = 5;
	STEAMLEARN_INFERENCE_ERROR_INVALID_TIMESTAMP = 6;
	STEAMLEARN_INFERENCE_ERROR_INVALID_PUBLISHED_VERSION = 7;
	STEAMLEARN_INFERENCE_ERROR_NO_FETCH_ID_FOUND = 8;
	STEAMLEARN_INFERENCE_ERROR_TOO_BUSY = 9;
	STEAMLEARN_INFERENCE_ERROR_UNSUPPLIED_DATA_FAIL = 10;
	STEAMLEARN_INFERENCE_ERROR_UNSUPPLIED_DATA_NO_KEYS = 11;
	STEAMLEARN_INFERENCE_DISABLED = 12;
	STEAMLEARN_INFERENCE_ERROR_NO_OUTPUT = 13;
	STEAMLEARN_INFERENCE_ERROR_INVALID_NAMED_INFERENCE = 14;
}

enum ESteamLearnInferenceMetadataResult {
	STEAMLEARN_INFERENCE_METADATA_ERROR = 0;
	STEAMLEARN_INFERENCE_METADATA_SUCCESS = 1;
	STEAMLEARN_INFERENCE_METADATA_ERROR_INVALID_PROJECT_ID = 2;
	STEAMLEARN_INFERENCE_METADATA_ERROR_NO_PUBLISHED_CONFIG = 3;
	STEAMLEARN_INFERENCE_METADATA_ERROR_FORBIDDEN = 4;
	STEAMLEARN_INFERENCE_METADATA_ERROR_INVALID_TIMESTAMP = 5;
	STEAMLEARN_INFERENCE_METADATA_ERROR_INVALID_PUBLISHED_VERSION = 6;
	STEAMLEARN_INFERENCE_METADATA_ERROR_NO_FETCH_ID_FOUND = 7;
}

message CMsgSteamLearnDataSourceDescObject {
	repeated .CMsgSteamLearnDataSourceDescElement elements = 1;
}

message CMsgSteamLearnDataSourceDescElement {
	optional string name = 1;
	optional .ESteamLearnDataType data_type = 2 [default = STEAMLEARN_DATATYPE_INVALID];
	optional .CMsgSteamLearnDataSourceDescObject object = 3;
	optional uint32 count = 4;
}

message CMsgSteamLearnDataSource {
	optional uint32 id = 1;
	optional string name = 2;
	optional uint32 version = 3;
	optional string source_description = 4;
	optional .CMsgSteamLearnDataSourceDescObject structure = 5;
	optional uint32 structure_crc = 6;
	optional uint32 cache_duration_seconds = 7;
}

message CMsgSteamLearnDataObject {
	repeated .CMsgSteamLearnDataElement elements = 1;
}

message CMsgSteamLearnDataElement {
	optional string name = 1;
	repeated int32 data_int32s = 20;
	repeated float data_floats = 21;
	repeated bool data_bools = 22;
	repeated string data_strings = 23;
	repeated .CMsgSteamLearnDataObject data_objects = 24;
}

message CMsgSteamLearnData {
	optional uint32 data_source_id = 1;
	repeated uint64 keys = 2;
	optional .CMsgSteamLearnDataObject data_object = 3;
}

message CMsgSteamLearnDataList {
	repeated .CMsgSteamLearnData data = 1;
}

message CMsgSteamLearn_RegisterDataSource_Request {
	optional string access_token = 1;
	optional .CMsgSteamLearnDataSource data_source = 3;
}

message CMsgSteamLearn_RegisterDataSource_Response {
	optional .ESteammLearnRegisterDataSourceResult result = 1 [default = STEAMLEARN_REGISTER_DATA_SOURCE_RESULT_ERROR];
	optional .CMsgSteamLearnDataSource data_source = 2;
}

message CMsgSteamLearn_CacheData_Request {
	optional string access_token = 1;
	optional .CMsgSteamLearnData data = 3;
}

message CMsgSteamLearn_CacheData_Response {
	optional .ESteamLearnCacheDataResult cache_data_result = 1 [default = STEAMLEARN_CACHE_DATA_ERROR];
}

message CMsgSteamLearn_SnapshotProject_Request {
	optional string access_token = 1;
	optional uint32 project_id = 3;
	optional uint32 published_version = 7;
	repeated uint64 keys = 4;
	repeated .CMsgSteamLearnData data = 5;
	optional uint32 pending_data_limit_seconds = 6;
}

message CMsgSteamLearn_SnapshotProject_Response {
	optional .ESteamLearnSnapshotProjectResult snapshot_result = 1 [default = STEAMLEARN_SNAPSHOT_PROJECT_ERROR];
}

message CMsgSteamLearn_BatchOperation_Request {
	repeated .CMsgSteamLearn_CacheData_Request cache_data_requests = 1;
	repeated .CMsgSteamLearn_SnapshotProject_Request snapshot_requests = 2;
	repeated .CMsgSteamLearn_Inference_Request inference_requests = 3;
}

message CMsgSteamLearn_BatchOperation_Response {
	repeated .CMsgSteamLearn_CacheData_Response cache_data_responses = 1;
	repeated .CMsgSteamLearn_SnapshotProject_Response snapshot_responses = 2;
	repeated .CMsgSteamLearn_Inference_Response inference_responses = 3;
}

message CMsgSteamLearnAccessTokens {
	message CacheDataAccessToken {
		optional uint32 data_source_id = 1;
		optional string access_token = 2;
	}

	message SnapshotProjectAccessToken {
		optional uint32 project_id = 1;
		optional string access_token = 2;
	}

	message InferenceAccessToken {
		optional uint32 project_id = 1;
		optional string access_token = 2;
	}

	optional string register_data_source_access_token = 1;
	repeated .CMsgSteamLearnAccessTokens.CacheDataAccessToken cache_data_access_tokens = 2;
	repeated .CMsgSteamLearnAccessTokens.SnapshotProjectAccessToken snapshot_project_access_tokens = 3;
	repeated .CMsgSteamLearnAccessTokens.InferenceAccessToken inference_access_tokens = 4;
}

message CMsgSteamLearn_GetAccessTokens_Request {
	optional uint32 appid = 1;
}

message CMsgSteamLearn_GetAccessTokens_Response {
	optional .ESteamLearnGetAccessTokensResult result = 1 [default = STEAMLEARN_GET_ACCESS_TOKENS_ERROR];
	optional .CMsgSteamLearnAccessTokens access_tokens = 2;
}

message CMsgInferenceIterateBeamSearch {
	message CustomItemScalar {
		optional uint32 item = 1;
		optional float scale = 2;
	}

	optional uint32 beam_length = 1;
	optional uint32 beam_width = 2;
	optional float item_decay = 3;
	optional uint32 next_item_count = 4;
	repeated .CMsgInferenceIterateBeamSearch.CustomItemScalar item_scalars = 5;
	optional uint32 item_sequence_end = 7;
	optional float item_sequence_end_threshold = 8;
	optional float repeat_multiplier = 9;
}

message CMsgSteamLearn_Inference_Request {
	optional string access_token = 1;
	optional uint32 project_id = 3;
	optional uint32 published_version = 4;
	optional uint32 override_train_id = 5;
	optional .CMsgSteamLearnDataList data = 6;
	repeated float additional_data = 7;
	repeated uint64 keys = 8;
	optional string named_inference = 9;
	optional .CMsgInferenceIterateBeamSearch iterate_beam_search = 13;
	optional uint32 debug_spew = 14;
}

message CMsgSteamLearn_InferenceMetadata_Request {
	optional string access_token = 1;
	optional uint32 project_id = 3;
	optional uint32 published_version = 4;
	optional uint32 override_train_id = 5;
}

message CMsgSteamLearn_InferenceMetadataBackend_Request {
	optional uint32 project_id = 1;
	optional uint32 fetch_id = 2;
}

message CMsgSteamLearn_InferenceMetadata_Response {
	message RowRange {
		optional uint64 min_row = 1;
		optional uint64 max_row = 2;
	}

	message Range {
		optional string data_element_path = 1;
		optional float min_value = 2;
		optional float max_value = 3;
	}

	message StdDev {
		optional string data_element_path = 1;
		optional float mean = 2;
		optional float std_dev = 3;
	}

	message CompactTable {
		message Entry {
			optional uint32 value = 1;
			optional uint32 mapping = 2;
			optional uint64 count = 3;
		}

		message MapValuesEntry {
			optional uint32 key = 1;
			optional .CMsgSteamLearn_InferenceMetadata_Response.CompactTable.Entry value = 2;
		}

		message MapMappingsEntry {
			optional uint32 key = 1;
			optional .CMsgSteamLearn_InferenceMetadata_Response.CompactTable.Entry value = 2;
		}

		optional string name = 1;
		repeated .CMsgSteamLearn_InferenceMetadata_Response.CompactTable.MapValuesEntry map_values = 2;
		repeated .CMsgSteamLearn_InferenceMetadata_Response.CompactTable.MapMappingsEntry map_mappings = 3;
	}

	message SequenceTable {
		message Entry {
			repeated uint32 values = 1;
			optional uint32 crc = 2;
			optional uint32 count = 3;
		}

		message MapValuesEntry {
			optional uint32 key = 1;
			optional .CMsgSteamLearn_InferenceMetadata_Response.SequenceTable.Entry value = 2;
		}

		message MapMappingsEntry {
			optional string key = 1;
			optional .CMsgSteamLearn_InferenceMetadata_Response.SequenceTable.Entry value = 2;
		}

		optional string name = 1;
		repeated .CMsgSteamLearn_InferenceMetadata_Response.SequenceTable.MapValuesEntry map_values = 2;
		repeated .CMsgSteamLearn_InferenceMetadata_Response.SequenceTable.MapMappingsEntry map_mappings = 3;
		optional uint64 total_count = 4;
	}

	message KMeans {
		message Cluster {
			optional float x = 1;
			optional float y = 2;
			optional float radius = 3;
			optional float radius_75pct = 4;
			optional float radius_50pct = 5;
			optional float radius_25pct = 6;
		}

		optional string name = 1;
		repeated .CMsgSteamLearn_InferenceMetadata_Response.KMeans.Cluster clusters = 2;
	}

	message SnapshotHistogram {
		optional float min_value = 1;
		optional float max_value = 2;
		optional uint32 num_buckets = 3;
		repeated uint32 bucket_counts = 4;
	}

	message AppInfo {
		optional string country_allow = 1;
		optional string country_deny = 2;
		optional bool platform_win = 3;
		optional bool platform_mac = 4;
		optional bool platform_linux = 5;
		optional bool adult_violence = 6;
		optional bool adult_sex = 7;
	}

	message AppInfoEntry {
		optional uint32 key = 1;
		optional .CMsgSteamLearn_InferenceMetadata_Response.AppInfo value = 2;
	}

	optional .ESteamLearnInferenceMetadataResult inference_metadata_result = 1 [default = STEAMLEARN_INFERENCE_METADATA_ERROR];
	optional .CMsgSteamLearn_InferenceMetadata_Response.RowRange row_range = 2;
	repeated .CMsgSteamLearn_InferenceMetadata_Response.Range ranges = 3;
	repeated .CMsgSteamLearn_InferenceMetadata_Response.StdDev std_devs = 4;
	repeated .CMsgSteamLearn_InferenceMetadata_Response.CompactTable compact_tables = 5;
	repeated .CMsgSteamLearn_InferenceMetadata_Response.SequenceTable sequence_tables = 9;
	repeated .CMsgSteamLearn_InferenceMetadata_Response.KMeans kmeans = 6;
	repeated .CMsgSteamLearn_InferenceMetadata_Response.AppInfoEntry app_info = 8;
	optional .CMsgSteamLearn_InferenceMetadata_Response.SnapshotHistogram snapshot_histogram = 7;
}

message CMsgSteamLearn_InferenceBackend_Response {
	message Sequence {
		repeated float value = 1;
	}

	message RegressionOutput {
		optional float value = 2;
	}

	message NamedInferenceOutput {
		repeated float value = 3;
	}

	message BinaryCrossEntropyOutput {
		optional float value = 1;
	}

	message MutliBinaryCrossEntropyOutput {
		repeated float weight = 1;
		repeated float value = 2;
		repeated .CMsgSteamLearn_InferenceBackend_Response.Sequence value_sequence = 3;
	}

	message CategoricalCrossEntropyOutput {
		repeated float weight = 1;
		repeated float value = 2;
		repeated .CMsgSteamLearn_InferenceBackend_Response.Sequence value_sequence = 3;
	}

	message Output {
		oneof ResponseType {
			.CMsgSteamLearn_InferenceBackend_Response.BinaryCrossEntropyOutput binary_crossentropy = 1;
			.CMsgSteamLearn_InferenceBackend_Response.CategoricalCrossEntropyOutput categorical_crossentropy = 2;
			.CMsgSteamLearn_InferenceBackend_Response.MutliBinaryCrossEntropyOutput multi_binary_crossentropy = 3;
			.CMsgSteamLearn_InferenceBackend_Response.RegressionOutput regression = 4;
			.CMsgSteamLearn_InferenceBackend_Response.NamedInferenceOutput named_inference = 5;
		}
	}

	repeated .CMsgSteamLearn_InferenceBackend_Response.Output outputs = 1;
}

message CMsgSteamLearn_Inference_Response {
	optional .ESteamLearnInferenceResult inference_result = 1 [default = STEAMLEARN_INFERENCE_ERROR];
	optional .CMsgSteamLearn_InferenceBackend_Response backend_response = 2;
	repeated uint64 keys = 3;
}

service SteamLearn {
	option (service_description) = "Service for submitting data, training, and inferencing with SteamLearn.";

	rpc RegisterDataSource (.CMsgSteamLearn_RegisterDataSource_Request) returns (.CMsgSteamLearn_RegisterDataSource_Response) {
		option (method_description) = "Registers a data desc (or finds a data desc if it's already registered).";
	}

	rpc CacheData (.CMsgSteamLearn_CacheData_Request) returns (.CMsgSteamLearn_CacheData_Response) {
		option (method_description) = "Updates a cached data entry.";
	}

	rpc SnapshotProject (.CMsgSteamLearn_SnapshotProject_Request) returns (.CMsgSteamLearn_SnapshotProject_Response) {
		option (method_description) = "Snapshots the current data for a project.";
	}

	rpc BatchOperation (.CMsgSteamLearn_BatchOperation_Request) returns (.CMsgSteamLearn_BatchOperation_Response) {
		option (method_description) = "Batches multiple data updates, snapshots, and inference requests into a single call";
	}

	rpc GetAccessTokens (.CMsgSteamLearn_GetAccessTokens_Request) returns (.CMsgSteamLearn_GetAccessTokens_Response) {
		option (method_description) = "Gets the access tokens needed for registering data sources, submitting data to them, and snapshotting projects";
	}

	rpc Inference (.CMsgSteamLearn_Inference_Request) returns (.CMsgSteamLearn_Inference_Response) {
		option (method_description) = "Inferences using supplied data, or data associated with the specified key.";
	}

	rpc InferenceMetadata (.CMsgSteamLearn_InferenceMetadata_Request) returns (.CMsgSteamLearn_InferenceMetadata_Response) {
		option (method_description) = "Requests the metadata that was generated from a specified fetch.";
	}
}
