import {z} from 'zod' export type Region = 'JP' | 'NA' | 'CN' | 'KR' | 'TW'; export type GetApiNiceRegionBattleMessageMessageIdArgs = {region: Region, message_id: number}; export type GetApiNiceRegionBattleMessageMessageIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const niceCondType = z.enum(["none", "questClear", "itemGet", "useItemEternity", "useItemTime", "useItemCount", "svtLevel", "svtLimit", "svtGet", "svtFriendship", "svtGroup", "event", "date", "weekday", "purchaseQpShop", "purchaseStoneShop", "warClear", "flag", "svtCountStop", "birthDay", "eventEnd", "svtEventJoin", "missionConditionDetail", "eventMissionClear", "eventMissionAchieve", "questClearNum", "notQuestGroupClear", "raidAlive", "raidDead", "raidDamage", "questChallengeNum", "masterMission", "questGroupClear", "superBossDamage", "superBossDamageAll", "purchaseShop", "questNotClear", "notShopPurchase", "notSvtGet", "notEventShopPurchase", "svtHaving", "notSvtHaving", "questChallengeNumEqual", "questChallengeNumBelow", "questClearNumEqual", "questClearNumBelow", "questClearPhase", "notQuestClearPhase", "eventPointGroupWin", "eventNormaPointClear", "questAvailable", "questGroupAvailableNum", "eventNormaPointNotClear", "notItemGet", "costumeGet", "questResetAvailable", "svtGetBeforeEventEnd", "questClearRaw", "questGroupClearRaw", "eventGroupPointRatioInTerm", "eventGroupRankInTerm", "notEventRaceQuestOrNotAllGroupGoal", "eventGroupTotalWinEachPlayer", "eventScriptPlay", "svtCostumeReleased", "questNotClearAnd", "svtRecoverd", "shopReleased", "eventPoint", "eventRewardDispCount", "equipWithTargetCostume", "raidGroupDead", "notSvtGroup", "notQuestResetAvailable", "notQuestClearRaw", "notQuestGroupClearRaw", "notEventMissionClear", "notEventMissionAchieve", "notCostumeGet", "notSvtCostumeReleased", "notEventRaceQuestOrNotTargetRankGoal", "playerGenderType", "shopGroupLimitNum", "eventGroupPoint", "eventGroupPointBelow", "eventTotalPoint", "eventTotalPointBelow", "eventValue", "eventValueBelow", "eventFlag", "eventStatus", "notEventStatus", "forceFalse", "svtHavingLimitMax", "eventPointBelow", "svtEquipFriendshipHaving", "movieNotDownload", "multipleDate", "svtFriendshipAbove", "svtFriendshipBelow", "movieDownloaded", "routeSelect", "notRouteSelect", "limitCount", "limitCountAbove", "limitCountBelow", "badEndPlay", "commandCodeGet", "notCommandCodeGet", "allUsersBoxGachaCount", "totalTdLevel", "totalTdLevelAbove", "totalTdLevelBelow", "commonRelease", "battleResultWin", "battleResultLose", "eventValueEqual", "boardGameTokenHaving", "boardGameTokenGroupHaving", "eventFlagOn", "eventFlagOff", "questStatusFlagOn", "questStatusFlagOff", "eventValueNotEqual", "limitCountMaxEqual", "limitCountMaxAbove", "limitCountMaxBelow", "boardGameTokenGetNum", "battleLineWinAbove", "battleLineLoseAbove", "battleLineContinueWin", "battleLineContinueLose", "battleLineContinueWinBelow", "battleLineContinueLoseBelow", "battleGroupWinAvove", "battleGroupLoseAvove", "svtLimitClassNum", "overTimeLimitRaidAlive", "onTimeLimitRaidDead", "onTimeLimitRaidDeadNum", "raidBattleProgressAbove", "svtEquipRarityLevelNum", "latestMainScenarioWarClear", "eventMapValueContains", "resetBirthDay", "shopFlagOn", "shopFlagOff", "purchaseValidShopGroup", "svtLevelClassNum", "svtLevelIdNum", "limitCountImageEqual", "limitCountImageAbove", "limitCountImageBelow", "eventTypeStartTimeToEndDate", "existBoxGachaScriptReplaceGiftId", "notExistBoxGachaScriptReplaceGiftId", "limitedPeriodVoiceChangeTypeOn", "startRandomMission", "randomMissionClearNum", "progressValueEqual", "progressValueAbove", "progressValueBelow", "randomMissionTotalClearNum", "weekdays", "eventFortificationRewardNum", "questClearBeforeEventStart", "notQuestClearBeforeEventStart", "eventTutorialFlagOn", "eventTutorialFlagOff", "eventSuperBossValueEqual", "notEventSuperBossValueEqual", "allSvtTargetSkillLvNum", "superBossDamageAbove", "superBossDamageBelow", "eventMissionGroupAchieve", "svtFriendshipClassNumAbove", "notWarClear", "svtSkillLvClassNumAbove", "svtClassLvUpCount", "svtClassSkillLvUpCount", "svtClassLimitUpCount", "svtClassFriendshipCount", "completeHeelPortrait", "notCompleteHeelPortrait", "classBoardSquareReleased", "svtLevelExchangeSvt", "svtLimitExchangeSvt", "skillLvExchangeSvt", "svtFriendshipExchangeSvt", "exchangeSvt", "raidDamageAbove", "raidDamageBelow", "raidGroupDamageAbove", "raidGroupDamageBelow", "raidDamageRateAbove", "raidDamageRateBelow", "raidDamageRateNotAbove", "raidDamageRateNotBelow", "raidGroupDamageRateAbove", "raidGroupDamageRateBelow", "raidGroupDamageRateNotAbove", "raidGroupDamageRateNotBelow", "notQuestGroupClearNum", "raidGroupOpenAbove", "raidGroupOpenBelow", "treasureDeviceAccelerate", "playQuestPhase", "notPlayQuestPhase", "eventStartToEnd", "commonValueAbove", "commonValueBelow", "commonValueEqual", "elapsedTimeAfterQuestClear", "withStartingMember", "latestQuestPhaseEqual", "notLatestQuestPhaseEqual", "purchaseShopNum", "eventTradeTotalNum", "limitedMissionAchieveNumBelow", "limitedMissionAchieveNumAbove", "notSvtVoicePlayed", "battlePointAbove", "battlePointBelow", "beforeSpecifiedDate", "notHaveChargeStone", "haveChargeStone", "battleFunctionTargetAllIndividuality", "battleFunctionTargetOneIndividuality", "beforeQuestClearTime", "afterQuestClearTime", "notBattleFunctionTargetAllIndividuality", "notBattleFunctionTargetOneIndividuality", "eventScriptNotPlay", "eventScriptFlag", "imagePartsGroup", "userLevelAbove", "userLevelBelow", "userLevelEqual", "highestWaveAbove", "highestWaveBelow", "privilegeValid", "privilegeInvalid", "battleActionOpponentIndividuality", "notBattleActionOpponentIndividuality", "treasureDeviceOfSelectedCard", "battleSvtFriendshipAbove", "battleSvtFriendshipBelow", "elapsedTimeAfterSvtGet", "notElapsedTimeAfterQuestClear", "notElapsedTimeAfterSvtGet", "grandSvtSet", "playedMovie", "notPlayedMovie", "notShopGroupLimitNum", "equipGet", "notEquipGet", "svtGetBeforeDate", "svtGetAfterDate", "notQuestAvailable", "notImagePartsGroup", "useEventPassiveSkillGivenItem", "notUseEventPassiveSkillGivenItem", "selfIndividuality", "notSelfIndividuality", "battleValueAbove", "battleValueBelow", "battleValueEqual", "battleValueNotEqual", "battlePointEqual", "battlePointNotEqual", "battleEntryPlayerTotalCountAbove", "battleEntryPlayerTotalCountBelow", "battleEntryPlayerTotalCountEqual", "battleEntryEnemyTotalCountAbove", "battleEntryEnemyTotalCountBelow", "battleEntryEnemyTotalCountEqual", "jobMaxLevelNumAbove", "jobMaxLevelNumBelow", "jobMaxLevelNumEqual", "svtHpReachNum", "svtAtkReachNum", "favoriteSvtIdEqual", "eventBallotSubmitted", "eventBallotNotSubmitted"]); export const niceCommonRelease = z.object({id: z.number().int(), priority: z.number().int(), condGroup: z.number().int(), condType: niceCondType, condId: z.number().int(), condNum: z.number().int()}); export const niceBattleMessage = z.object({id: z.number().int(), idx: z.number().int(), priority: z.number().int(), releaseConditions: z.array(niceCommonRelease), motionId: z.number().int(), message: z.string(), script: z.record(z.string(), z.unknown())}); export const getApiNiceRegionBattleMessageMessageIdResponse = z.array(niceBattleMessage); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Get Battle Message data * * GET /nice/{region}/battle-message/{message_id} */ export const getApiNiceRegionBattleMessageMessageId = async (args: GetApiNiceRegionBattleMessageMessageIdArgs, options?: GetApiNiceRegionBattleMessageMessageIdOptions) => { const {baseUrl = "https://api.atlasacademy.io", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/nice/${encodeURIComponent(String(args.region))}/battle-message/${encodeURIComponent(String(args.message_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiNiceRegionBattleMessageMessageIdResponse, await res.json()) };