import {z} from 'zod' export type WheelPrizeType = 'subscription_days' | 'balance_bonus' | 'traffic_gb' | 'promocode' | 'nothing'; export type UpdatePrizeRequest = {prize_type?: (WheelPrizeType | null) | undefined, prize_value?: (number | null) | undefined, display_name?: (string | null) | undefined, emoji?: (string | null) | undefined, color?: (string | null) | undefined, prize_value_kopeks?: (number | null) | undefined, sort_order?: (number | null) | undefined, manual_probability?: (number | null) | undefined, is_active?: (boolean | null) | undefined, promo_balance_bonus_kopeks?: (number | null) | undefined, promo_subscription_days?: (number | null) | undefined, promo_traffic_gb?: (number | null) | undefined}; export type UpdateApiCabinetAdminWheelPrizesPrizeIdArgs = {prize_id: number, body: UpdatePrizeRequest}; export type UpdateApiCabinetAdminWheelPrizesPrizeIdOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const wheelPrizeAdminResponse = z.object({id: z.number().int(), config_id: z.number().int(), prize_type: z.string(), prize_value: z.number().int(), display_name: z.string(), emoji: z.string(), color: z.string(), prize_value_kopeks: z.number().int(), sort_order: z.number().int(), manual_probability: z.number().nullable().optional(), is_active: z.boolean(), promo_balance_bonus_kopeks: z.number().int().optional(), promo_subscription_days: z.number().int().optional(), promo_traffic_gb: z.number().int().optional(), created_at: z.string().nullable().optional(), updated_at: z.string().nullable().optional()}); 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 }; /** * Update Prize * * PUT /cabinet/admin/wheel/prizes/{prize_id} */ export const updateApiCabinetAdminWheelPrizesPrizeId = async (args: UpdateApiCabinetAdminWheelPrizesPrizeIdArgs, options: UpdateApiCabinetAdminWheelPrizesPrizeIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/cabinet/admin/wheel/prizes/${encodeURIComponent(String(args.prize_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(wheelPrizeAdminResponse, await res.json()) };