syntax = "proto3";

package retrom;

import 'retrom/jobs.proto';
import 'retrom/models/clients.proto';
import 'retrom/models/emulators.proto';
import 'retrom/models/game-files.proto';
import 'retrom/models/games.proto';
import 'retrom/models/metadata.proto';
import 'retrom/models/platforms.proto';
import 'retrom/providers/igdb.proto';
import 'retrom/server/server-info.proto';

service LibraryService {
  rpc UpdateLibrary(UpdateLibraryRequest) returns (UpdateLibraryResponse);
  rpc UpdateLibraryMetadata(UpdateLibraryMetadataRequest) returns (UpdateLibraryMetadataResponse);
  rpc DeleteLibrary(DeleteLibraryRequest) returns (DeleteLibraryResponse);
}

service PlatformService {
  rpc GetPlatforms(GetPlatformsRequest) returns (GetPlatformsResponse);
  rpc DeletePlatforms(DeletePlatformsRequest) returns (DeletePlatformsResponse);
  rpc UpdatePlatforms(UpdatePlatformsRequest) returns (UpdatePlatformsResponse);
}

service GameService {
  rpc GetGames(GetGamesRequest) returns (GetGamesResponse);
  rpc DeleteGames(DeleteGamesRequest) returns (DeleteGamesResponse);
  rpc UpdateGames(UpdateGamesRequest) returns (UpdateGamesResponse);

  rpc DeleteGameFiles(DeleteGameFilesRequest) returns (DeleteGameFilesResponse);
  rpc UpdateGameFiles(UpdateGameFilesRequest) returns (UpdateGameFilesResponse);
}

service MetadataService {
  rpc GetGameMetadata(GetGameMetadataRequest) returns (GetGameMetadataResponse);
  rpc UpdateGameMetadata(UpdateGameMetadataRequest) returns (UpdateGameMetadataResponse);

  rpc GetPlatformMetadata(GetPlatformMetadataRequest) returns (GetPlatformMetadataResponse);
  rpc UpdatePlatformMetadata(UpdatePlatformMetadataRequest) returns (UpdatePlatformMetadataResponse);

  rpc GetIgdbSearch(GetIgdbSearchRequest) returns (GetIgdbSearchResponse);
  rpc GetIgdbGameSearchResults(GetIgdbGameSearchResultsRequest) returns (GetIgdbGameSearchResultsResponse);
  rpc GetIgdbPlatformSearchResults(GetIgdbPlatformSearchResultsRequest) returns (GetIgdbPlatformSearchResultsResponse);
}

service ClientService {
  rpc CreateClient(CreateClientRequest) returns (CreateClientResponse);
  rpc GetClients(GetClientsRequest) returns (GetClientsResponse);
  rpc UpdateClients(UpdateClientsRequest) returns (UpdateClientsResponse);
  rpc DeleteClients(DeleteClientsRequest) returns (DeleteClientsResponse);
}

service ServerService {
  rpc GetServerInfo(GetServerInfoRequest) returns (GetServerInfoResponse);
}

service EmulatorService {
  rpc CreateEmulators(CreateEmulatorsRequest) returns (CreateEmulatorsResponse);
  rpc GetEmulators(GetEmulatorsRequest) returns (GetEmulatorsResponse);
  rpc UpdateEmulators(UpdateEmulatorsRequest) returns (UpdateEmulatorsResponse);
  rpc DeleteEmulators(DeleteEmulatorsRequest) returns (DeleteEmulatorsResponse);

  rpc CreateEmulatorProfiles(CreateEmulatorProfilesRequest) returns (CreateEmulatorProfilesResponse);
  rpc GetEmulatorProfiles(GetEmulatorProfilesRequest) returns (GetEmulatorProfilesResponse);
  rpc UpdateEmulatorProfiles(UpdateEmulatorProfilesRequest) returns (UpdateEmulatorProfilesResponse);
  rpc DeleteEmulatorProfiles(DeleteEmulatorProfilesRequest) returns (DeleteEmulatorProfilesResponse);

  rpc GetDefaultEmulatorProfiles(GetDefaultEmulatorProfilesRequest) returns (GetDefaultEmulatorProfilesResponse);
  rpc UpdateDefaultEmulatorProfiles(UpdateDefaultEmulatorProfilesRequest) returns (UpdateDefaultEmulatorProfilesResponse);
  rpc DeleteDefaultEmulatorProfiles(DeleteDefaultEmulatorProfilesRequest) returns (DeleteDefaultEmulatorProfilesResponse);
}

service JobService {
  rpc GetJobs(GetJobsRequest) returns (stream GetJobsResponse);
}

message UpdateLibraryRequest {}

message UpdateLibraryResponse {
  repeated Platform platforms_populated = 1;
  repeated Game games_populated = 2;
  repeated GameFile game_files_populated = 3;
}

message UpdateLibraryMetadataRequest {
  optional bool overwrite = 1;
}

message UpdateLibraryMetadataResponse {}

message GetPlatformsRequest {
  repeated int32 ids = 1;
  optional bool with_metadata = 2;
  optional bool include_deleted = 3;
}

message GetPlatformsResponse {
  repeated Platform platforms = 1;
  repeated PlatformMetadata metadata = 2;
}

message GetGamesRequest {
  repeated int32 platform_ids = 1;
  repeated int32 ids = 2;
  optional bool with_metadata = 3;
  optional bool with_files = 4;
  optional bool include_deleted = 5;
}

message GetGamesResponse {
  repeated Game games = 1;
  repeated GameMetadata metadata = 2;
  repeated GameFile game_files = 3;
}

message GetGameMetadataRequest {
  repeated int32 game_ids = 1;
}

message GetGameMetadataResponse {
  message GameGenres {
    repeated GameGenre value = 1;
  }

  message SimilarGames {
    repeated Game value = 1;
  }

  repeated GameMetadata metadata = 1;
  map<int32, SimilarGames> similar_games = 2;
  map<int32, GameGenres> genres = 3;
}

message GetPlatformMetadataRequest {
  repeated int32 platform_ids = 1;
}

message GetPlatformMetadataResponse {
  repeated PlatformMetadata metadata = 1;
}

message GetIgdbGameSearchResultsRequest {
  IgdbGameSearchQuery query = 1;
}

message GetIgdbGameSearchResultsResponse {
  repeated NewGameMetadata metadata = 1;
}

message UpdateGameMetadataRequest {
  repeated UpdatedGameMetadata metadata = 1;
}

message UpdateGameMetadataResponse {
  repeated GameMetadata metadata_updated = 1;
}

message GetIgdbPlatformSearchResultsRequest {
  IgdbPlatformSearchQuery query = 1;
}

message GetIgdbPlatformSearchResultsResponse {
  repeated NewPlatformMetadata metadata = 1;
}

message UpdatePlatformMetadataRequest {
  repeated UpdatedPlatformMetadata metadata = 1;
}

message UpdatePlatformMetadataResponse {
  repeated PlatformMetadata metadata_updated = 1;
}

// Arbitrary search query for IGDB
message GetIgdbSearchRequest {
  enum IgdbSearchType {
    GAME = 0;
    PLATFORM = 1;
  }

  IgdbSearchType search_type = 1;
  optional IgdbSearch search = 2;
  optional IgdbPagination pagination = 3;
  optional IgdbFilters filters = 4;
  optional IgdbFields fields = 5;
}

message IgdbSearchGameResponse {
  repeated NewGameMetadata games = 1;
}

message IgdbSearchPlatformResponse {
  repeated NewPlatformMetadata platforms = 1;
}

message GetIgdbSearchResponse {
  oneof search_results {
    IgdbSearchGameResponse game_matches = 1;
    IgdbSearchPlatformResponse platform_matches = 2;
  }
}

message DeleteLibraryRequest {}

message DeleteLibraryResponse {}

message DeletePlatformsRequest {
  repeated int32 ids = 1;
  bool delete_from_disk = 2;
}

message DeletePlatformsResponse {
  repeated Platform platforms_deleted = 1;
}

message UpdatePlatformsRequest {
  repeated UpdatedPlatform platforms = 1;
}

message UpdatePlatformsResponse {
  repeated Platform platforms_updated = 1;
}

message DeleteGamesRequest {
  repeated int32 ids = 1;
  bool delete_from_disk = 2;
}

message DeleteGamesResponse {
  repeated Game games_deleted = 1;
}

message UpdateGamesRequest {
  repeated UpdatedGame games = 1;
}

message UpdateGamesResponse {
  repeated Game games_updated = 1;
}

message CreateClientRequest {
  NewClient client = 1;
}

message CreateClientResponse {
  Client client_created = 1;
}

message GetClientsRequest {
  repeated int32 ids = 1;
  repeated string names = 2;
}

message GetClientsResponse {
  repeated Client clients = 1;
}

message UpdateClientsRequest {
  repeated UpdatedClient clients = 1;
}

message UpdateClientsResponse {
  repeated Client clients_updated = 1;
}

message DeleteClientsRequest {
  repeated int32 ids = 1;
}

message DeleteClientsResponse {
  repeated Client clients_deleted = 1;
}

message GetServerInfoRequest {}

message GetServerInfoResponse {
  ServerInfo server_info = 1;
}

message CreateEmulatorsRequest {
  repeated NewEmulator emulators = 1;
}

message CreateEmulatorsResponse {
  repeated Emulator emulators_created = 1;
}

message GetEmulatorsRequest {
  repeated int32 ids = 1;
  repeated int32 supported_platform_ids = 2;
}

message GetEmulatorsResponse {
  repeated Emulator emulators = 1;
}

message UpdateEmulatorsRequest {
  repeated UpdatedEmulator emulators = 1;
}

message UpdateEmulatorsResponse {
  repeated Emulator emulators_updated = 1;
}

message DeleteEmulatorsRequest {
  repeated int32 ids = 1;
}

message DeleteEmulatorsResponse {
  repeated Emulator emulators_deleted = 1;
}

message CreateEmulatorProfilesRequest {
  repeated NewEmulatorProfile profiles = 1;
}

message CreateEmulatorProfilesResponse {
  repeated EmulatorProfile profiles_created = 1;
}

message GetEmulatorProfilesRequest {
  repeated int32 ids = 1;
  repeated int32 emulator_ids = 2;
}

message GetEmulatorProfilesResponse {
  repeated EmulatorProfile profiles = 1;
}

message UpdateEmulatorProfilesRequest {
  repeated UpdatedEmulatorProfile profiles = 1;
}

message UpdateEmulatorProfilesResponse {
  repeated EmulatorProfile profiles_updated = 1;
}

message DeleteEmulatorProfilesRequest {
  repeated int32 ids = 1;
}

message DeleteEmulatorProfilesResponse {
  repeated EmulatorProfile profiles_deleted = 1;
}

message GetDefaultEmulatorProfilesRequest {
  repeated int32 platform_ids = 1;
}

message GetDefaultEmulatorProfilesResponse {
  repeated DefaultEmulatorProfile default_profiles = 1;
}

message UpdateDefaultEmulatorProfilesRequest {
  repeated UpdatedDefaultEmulatorProfile default_profiles = 1;
}

message UpdateDefaultEmulatorProfilesResponse {
  repeated DefaultEmulatorProfile default_profiles_updated = 1;
}

message DeleteDefaultEmulatorProfilesRequest {
  repeated int32 platform_ids = 1;
}

message DeleteDefaultEmulatorProfilesResponse {
  repeated DefaultEmulatorProfile default_profiles_deleted = 1;
}

message DeleteGameFilesRequest {
  repeated int32 ids = 1;
  bool delete_from_disk = 2;
}

message DeleteGameFilesResponse {
  repeated GameFile game_files_deleted = 1;
}

message UpdateGameFilesRequest {
  repeated UpdatedGameFile game_files = 1;
}

message UpdateGameFilesResponse {
  repeated GameFile game_files_updated = 1;
}

message GetJobsRequest {}

message GetJobsResponse {
  repeated JobProgress jobs = 1;
}
