import { operation, requestBodySchema, response200, response500, security, statusSchema, tags, } from '../chunks.ts'; const ALLIANCE_SORT_BY = [ 'average_empire_size_rank', 'offense_success_rate_rank', 'defense_success_rate_rank', 'dirtiest_rank', ]; const EMPIRE_SORT_BY = [ 'empire_size_rank', 'offense_success_rate_rank', 'defense_success_rate_rank', 'dirtiest_rank', ]; const COLONY_SORT_BY = ['population_rank']; const SPY_SORT_BY = ['level_rank', 'success_rate_rank', 'dirtiest_rank']; const pageNumberSchema = { type: 'integer', description: "Optional. 25 records per page. Defaults to the page containing the current user's own rank.", }; const allianceRankEntrySchema = { type: 'object', required: [ 'alliance_id', 'alliance_name', 'member_count', 'space_station_count', 'influence', 'colony_count', 'population', 'average_empire_size', 'building_count', 'average_building_level', 'offense_success_rate', 'defense_success_rate', 'dirtiest', ], properties: { alliance_id: { type: 'integer' }, alliance_name: { type: 'string' }, member_count: { type: 'integer' }, space_station_count: { type: 'integer' }, influence: { type: 'integer' }, colony_count: { type: 'integer' }, population: { type: 'integer' }, average_empire_size: { type: 'number' }, building_count: { type: 'integer' }, average_building_level: { type: 'number' }, offense_success_rate: { type: 'number' }, defense_success_rate: { type: 'number' }, dirtiest: { type: 'integer' }, }, }; const empireRankEntrySchema = { type: 'object', required: [ 'empire_id', 'empire_name', 'alliance_id', 'alliance_name', 'colony_count', 'population', 'empire_size', 'building_count', 'average_building_level', 'offense_success_rate', 'defense_success_rate', 'dirtiest', ], properties: { empire_id: { type: 'integer' }, empire_name: { type: 'string' }, alliance_id: { type: ['integer', 'null'], description: 'Always present, but null when the empire is not in an alliance.', }, alliance_name: { type: ['string', 'null'], description: 'Always present, but null when the empire is not in an alliance.', }, colony_count: { type: 'integer' }, population: { type: 'integer' }, empire_size: { type: 'integer' }, building_count: { type: 'integer' }, average_building_level: { type: 'number' }, offense_success_rate: { type: 'number' }, defense_success_rate: { type: 'number' }, dirtiest: { type: 'integer' }, }, }; const colonyRankEntrySchema = { type: 'object', required: [ 'empire_id', 'empire_name', 'planet_id', 'planet_name', 'population', 'building_count', 'average_building_level', 'highest_building_level', ], properties: { empire_id: { type: 'integer' }, empire_name: { type: 'string' }, planet_id: { type: 'integer' }, planet_name: { type: 'string' }, population: { type: 'integer' }, building_count: { type: 'integer' }, average_building_level: { type: 'number' }, highest_building_level: { type: 'integer' }, }, }; const spyRankEntrySchema = { type: 'object', required: [ 'empire_id', 'empire_name', 'spy_id', 'spy_name', 'age', 'level', 'success_rate', 'dirtiest', ], properties: { empire_id: { type: 'integer' }, empire_name: { type: 'string' }, spy_id: { type: 'integer' }, spy_name: { type: 'string' }, age: { type: 'integer' }, level: { type: 'integer' }, success_rate: { type: 'number' }, dirtiest: { type: 'integer' }, }, }; const medalWinnerSchema = { type: 'object', required: ['empire_id', 'empire_name', 'medal_name', 'medal_image', 'times_earned'], properties: { empire_id: { type: 'integer' }, empire_name: { type: 'string' }, medal_name: { type: 'string' }, medal_image: { type: 'string' }, times_earned: { type: 'integer' }, }, }; export const stats = { '/v2/stats/credits': { post: { ...tags('stats'), ...security(), ...operation( 'Get the game credits.', 'Retrieves the list of game credits. Each entry names a single contribution category and the people who worked on it.' ), responses: { ...response200( 'Retrieves the list of game credits. Each entry names a single contribution category and the people who worked on it.', { type: 'array', items: { type: 'object', description: 'Keyed by contribution category, e.g. "Game Server" or "Play Testers".', additionalProperties: { type: 'array', items: { type: 'string' } }, }, } ), ...response500(), }, }, }, '/v2/stats/alliance_rank': { post: { ...tags('stats'), ...security(), ...operation( 'Rank alliances by statistic.', 'Returns a sorted list of alliances ranked according to various stats.' ), ...requestBodySchema({ type: 'object', properties: { sort_by: { type: 'string', enum: ALLIANCE_SORT_BY, description: 'Optional. Defaults to average_empire_size_rank.', }, page_number: pageNumberSchema, }, }), responses: { ...response200('Returns a sorted list of alliances ranked by various statistics.', { type: 'object', required: ['alliances', 'total_alliances', 'page_number', 'status'], properties: { alliances: { type: 'array', items: allianceRankEntrySchema }, total_alliances: { type: 'integer' }, page_number: { type: 'integer' }, status: statusSchema(), }, }), ...response500(), }, }, }, '/v2/stats/find_alliance_rank': { post: { ...tags('stats'), ...security(), ...operation( 'Find an alliance in the rankings.', 'Searches for a particular alliance within the alliance rankings, returning the page of the alliance_rank listing each match appears on.' ), ...requestBodySchema({ type: 'object', required: ['sort_by', 'alliance_name'], properties: { sort_by: { type: 'string', enum: ALLIANCE_SORT_BY, description: 'Determines which ranking the returned page numbers refer to.', }, alliance_name: { type: 'string', description: 'Full or partial name. Must be at least 3 characters.', }, }, }), responses: { ...response200( 'Searches for a particular alliance within the alliance rankings, returning the page of the alliance_rank listing each match appears on.', { type: 'object', required: ['alliances', 'status'], properties: { alliances: { type: 'array', items: { type: 'object', required: ['alliance_id', 'alliance_name', 'page_number'], properties: { alliance_id: { type: 'integer' }, alliance_name: { type: 'string' }, page_number: { type: 'integer' }, }, }, }, status: statusSchema(), }, } ), ...response500(), }, }, }, '/v2/stats/empire_rank': { post: { ...tags('stats'), ...security(), ...operation( 'Rank empires by statistic.', 'Returns a sorted list of empires ranked according to various stats.' ), ...requestBodySchema({ type: 'object', properties: { sort_by: { type: 'string', enum: EMPIRE_SORT_BY, description: 'Optional. Defaults to empire_size_rank.', }, page_number: pageNumberSchema, }, }), responses: { ...response200('Returns a sorted list of empires ranked by various statistics.', { type: 'object', required: ['empires', 'total_empires', 'page_number', 'status'], properties: { empires: { type: 'array', items: empireRankEntrySchema }, total_empires: { type: 'integer' }, page_number: { type: 'integer' }, status: statusSchema(), }, }), ...response500(), }, }, }, '/v2/stats/find_empire_rank': { post: { ...tags('stats'), ...security(), ...operation( 'Find an empire in the rankings.', 'Searches for a particular empire within the empire rankings, returning the page of the empire_rank listing each match appears on.' ), ...requestBodySchema({ type: 'object', required: ['sort_by', 'empire_name'], properties: { sort_by: { type: 'string', enum: EMPIRE_SORT_BY, description: 'Determines which ranking the returned page numbers refer to.', }, empire_name: { type: 'string', description: 'Full or partial name. Must be at least 3 characters.', }, }, }), responses: { ...response200( 'Searches for a particular empire within the empire rankings, returning the page of the empire_rank listing each match appears on.', { type: 'object', required: ['empires', 'status'], properties: { empires: { type: 'array', items: { type: 'object', required: ['empire_id', 'empire_name', 'page_number'], properties: { empire_id: { type: 'integer' }, empire_name: { type: 'string' }, page_number: { type: 'integer' }, }, }, }, status: statusSchema(), }, } ), ...response500(), }, }, }, '/v2/stats/colony_rank': { post: { ...tags('stats'), ...security(), ...operation( 'Rank colonies by statistic.', 'Returns a sorted list of planets ranked according to various stats.' ), ...requestBodySchema({ type: 'object', properties: { sort_by: { type: 'string', enum: COLONY_SORT_BY, description: 'Optional. Defaults to population_rank.', }, }, }), responses: { ...response200('Returns a sorted list of planets ranked by various statistics.', { type: 'object', required: ['colonies', 'status'], properties: { colonies: { type: 'array', items: colonyRankEntrySchema }, status: statusSchema(), }, }), ...response500(), }, }, }, '/v2/stats/spy_rank': { post: { ...tags('stats'), ...security(), ...operation( 'Rank the top spies by statistic.', 'Returns a sorted list of the top spies in the game ranked according to various stats.' ), ...requestBodySchema({ type: 'object', properties: { sort_by: { type: 'string', enum: SPY_SORT_BY, description: 'Optional. Defaults to level_rank.', }, }, }), responses: { ...response200('Returns a sorted list of the top spies ranked by various statistics.', { type: 'object', required: ['spies', 'status'], properties: { spies: { type: 'array', items: spyRankEntrySchema }, status: statusSchema(), }, }), ...response500(), }, }, }, '/v2/stats/weekly_medal_winners': { post: { ...tags('stats'), ...security(), ...operation( "List this week's medal winners.", "Returns the list of empires who won this week's weekly medals." ), responses: { ...response200("Returns the list of empires who won this week's weekly medals.", { type: 'object', required: ['winners', 'status'], properties: { winners: { type: 'array', items: medalWinnerSchema }, status: statusSchema(), }, }), ...response500(), }, }, }, };