import {z} from 'zod' export type ReferralContestUpdateRequest = {title?: (string | null) | undefined, description?: (string | null) | undefined, prize_text?: (string | null) | undefined, contest_type?: (string | null) | undefined, start_at?: (string | null) | undefined, end_at?: (string | null) | undefined, daily_summary_time?: (string | null) | undefined, daily_summary_times?: (string | null) | undefined, timezone?: (string | null) | undefined, is_active?: (boolean | null) | undefined, final_summary_sent?: (boolean | null) | undefined, created_by?: (number | null) | undefined}; export type PatchApiContestsReferralContestIdArgs = {contest_id: number, body: ReferralContestUpdateRequest}; export type PatchApiContestsReferralContestIdOptions = {baseUrl: string, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const referralContestResponse = z.object({id: z.number().int(), title: z.string(), description: z.string().nullable().optional(), prize_text: z.string().nullable().optional(), contest_type: z.string(), start_at: z.string(), end_at: z.string(), daily_summary_time: z.string(), daily_summary_times: z.string().nullable().optional(), timezone: z.string(), is_active: z.boolean(), last_daily_summary_date: z.string().nullable().optional(), last_daily_summary_at: z.string().nullable().optional(), final_summary_sent: z.boolean(), created_by: z.number().int().nullable().optional(), created_at: z.string(), updated_at: z.string()}); 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 Referral * * PATCH /contests/referral/{contest_id} */ export const patchApiContestsReferralContestId = async (args: PatchApiContestsReferralContestIdArgs, options: PatchApiContestsReferralContestIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (APIKeyHeader !== undefined) headers.set("X-API-Key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/contests/referral/${encodeURIComponent(String(args.contest_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(referralContestResponse, await res.json()) };