import type { Args } from "./processing/args"; import { callSammoAPI, extractHttpMethod, GET, PATCH, POST, PUT, type APITail, type APICallT, type RawArgType, type ValidResponse, type InvalidResponse } from "./util/callSammoAPI"; export type { ValidResponse, InvalidResponse }; import { APIPathGen, NumVar, StrVar } from "./util/APIPathGen.js"; import type { BettingDetailResponse, BettingListResponse } from "./defs/API/Betting"; import type { ReserveBulkCommandResponse, ReserveCommandResponse, ReservedCommandResponse } from "./defs/API/Command"; import type { ChiefResponse } from "./defs/API/NationCommand"; import type { inheritBuffType } from "./defs/API/InheritAction"; import type { SetBlockWarResponse, GeneralListResponse as NationGeneralListResponse } from "./defs/API/Nation"; import type { UploadImageResponse } from "./defs/API/Misc"; import type { GeneralLogType, GetGeneralLogResponse, JoinArgs } from "./defs/API/General"; import type { GetConstResponse, GetCurrentHistoryResponse, GetDiplomacyResponse, GetHistoryResponse } from "./defs/API/Global"; import type { CachedMapResult, GeneralListResponse, MapResult } from "./defs"; const apiRealPath = { Betting: { Bet: PUT as APICallT<{ bettingID: number, bettingType: number[], amount: number, }>, GetBettingDetail: NumVar('betting_id', GET as APICallT ), GetBettingList: GET as APICallT<{ req?: 'bettingNation' | 'tournament' }, BettingListResponse>, }, Command: { GetReservedCommand: GET as APICallT, PushCommand: PUT as APICallT<{ amount: number }>, RepeatCommand: PUT as APICallT<{ amount: number }>, ReserveCommand: PUT as APICallT<{ turnList: number[], action: string, arg?: Args }, ReserveCommandResponse>, ReserveBulkCommand: PUT as APICallT<{ turnList: number[], action: string, arg?: Args }[], ReserveBulkCommandResponse>, }, General: { Join: POST as APICallT, GetGeneralLog: GET as APICallT<{ reqType: GeneralLogType, reqTo?: number }, GetGeneralLogResponse> }, Global: { GeneralList: GET as APICallT, GeneralListWithToken: GET as APICallT, GetConst: GET as APICallT, GetHistory: StrVar('serverID')( NumVar('year', NumVar('month', GET as APICallT ))), GetCurrentHistory: GET as APICallT, GetMap: GET as APICallT<{ neutralView?: 0 | 1, showMe?: 0 | 1, }, MapResult>, GetCachedMap: GET as APICallT, GetDiplomacy: GET as APICallT, ExecuteEngine: POST as APICallT, }, InheritAction: { BuyHiddenBuff: PUT as APICallT<{ type: inheritBuffType, level: number }>, BuyRandomUnique: PUT as APICallT, BuySpecificUnique: PUT as APICallT<{ item: string, amount: number, }>, ResetSpecialWar: PUT as APICallT, ResetTurnTime: PUT as APICallT, SetNextSpecialWar: PUT as APICallT<{ type: string, }>, }, Misc: { UploadImage: POST as APICallT<{ imageData: string, }, UploadImageResponse> }, NationCommand: { GetReservedCommand: GET as APICallT, PushCommand: PUT as APICallT<{ amount: number }>, RepeatCommand: PUT as APICallT<{ amount: number }>, ReserveCommand: PUT as APICallT<{ turnList: number[], action: string, arg?: Args }, ReserveCommandResponse>, ReserveBulkCommand: PUT as APICallT<{ turnList: number[], action: string, arg?: Args }[], ReserveBulkCommandResponse>, }, Nation: { GeneralList: GET as APICallT, SetNotice: PUT as APICallT<{ msg: string, }>, SetScoutMsg: PUT as APICallT<{ msg: string, }>, SetBill: PATCH as APICallT<{ amount: number, }>, SetRate: PATCH as APICallT<{ amount: number, }>, SetSecretLimit: PATCH as APICallT<{ amount: number, }>, SetBlockWar: PATCH as APICallT<{ value: boolean, }, SetBlockWarResponse>, SetBlockScout: PATCH as APICallT<{ value: boolean, }>, GetGeneralLog: GET as APICallT<{ generalID: number, reqType: GeneralLogType, reqTo?: number }, GetGeneralLogResponse> }, } as const; export const SammoAPI = APIPathGen(apiRealPath, (path: string[], tail: APITail, pathParam) => { const method = extractHttpMethod(tail); return (args?: RawArgType, returnError?: boolean) => { if (returnError) { return callSammoAPI(method, path.join('/'), args, pathParam, true); } return callSammoAPI(method, path.join('/'), args, pathParam); }; });