import {z} from 'zod' export type GetApiV3CfbOddsFormatLiveGameOddsLineMovementGameidArgs = {format: 'JSON' | 'XML', gameid: string}; export type GetApiV3CfbOddsFormatLiveGameOddsLineMovementGameidOptions = {baseUrl?: string | undefined, apiKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const gameOdd = z.object({GameOddId: z.number().int().optional(), Sportsbook: z.string().nullable().optional(), GameId: z.number().int().optional(), Created: z.string().nullable().optional(), Updated: z.string().nullable().optional(), HomeMoneyLine: z.number().int().nullable().optional(), AwayMoneyLine: z.number().int().nullable().optional(), DrawMoneyLine: z.number().int().nullable().optional(), HomePointSpread: z.number().nullable().optional(), AwayPointSpread: z.number().nullable().optional(), HomePointSpreadPayout: z.number().int().nullable().optional(), AwayPointSpreadPayout: z.number().int().nullable().optional(), OverUnder: z.number().nullable().optional(), OverPayout: z.number().int().nullable().optional(), UnderPayout: z.number().int().nullable().optional(), SportsbookId: z.number().int().nullable().optional(), OddType: z.string().nullable().optional(), SportsbookUrl: z.string().nullable().optional(), Unlisted: z.string().nullable().optional()}); export const gameInfo = z.object({GameId: z.number().int().optional(), Season: z.number().int().optional(), SeasonType: z.number().int().optional(), Week: z.number().int().nullable().optional(), Day: z.string().nullable().optional(), DateTime: z.string().nullable().optional(), Status: z.string().nullable().optional(), AwayTeamId: z.number().int().nullable().optional(), HomeTeamId: z.number().int().nullable().optional(), AwayTeamName: z.string().nullable().optional(), HomeTeamName: z.string().nullable().optional(), GlobalGameId: z.number().int().optional(), GlobalAwayTeamId: z.number().int().nullable().optional(), GlobalHomeTeamId: z.number().int().nullable().optional(), PregameOdds: z.array(gameOdd).optional(), LiveOdds: z.array(gameOdd).optional(), HomeTeamScore: z.number().int().nullable().optional(), AwayTeamScore: z.number().int().nullable().optional(), TotalScore: z.number().int().nullable().optional(), HomeRotationNumber: z.number().int().nullable().optional(), AwayRotationNumber: z.number().int().nullable().optional(), AlternateMarketPregameOdds: z.array(gameOdd).optional()}); export const getApiV3CfbOddsFormatLiveGameOddsLineMovementGameidResponse = z.array(gameInfo); 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 }; /** * In-Game Odds Line Movement * * GET /v3/cfb/odds/{format}/LiveGameOddsLineMovement/{gameid} * * Also accepts auth: apiKeyQuery */ export const getApiV3CfbOddsFormatLiveGameOddsLineMovementGameid = async (args: GetApiV3CfbOddsFormatLiveGameOddsLineMovementGameidArgs, options?: GetApiV3CfbOddsFormatLiveGameOddsLineMovementGameidOptions) => { const {baseUrl = "https://api.sportsdata.io", fetch: fetchFn = fetch, apiKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (apiKeyHeader !== undefined) headers.set("Ocp-Apim-Subscription-Key", apiKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/v3/cfb/odds/${encodeURIComponent(String(args.format))}/LiveGameOddsLineMovement/${encodeURIComponent(String(args.gameid))}${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(getApiV3CfbOddsFormatLiveGameOddsLineMovementGameidResponse, await res.json()) };