import {z} from 'zod' export type PromoOfferTemplateUpdateRequest = {name?: (string | null) | undefined, message_text?: (string | null) | undefined, button_text?: (string | null) | undefined, valid_hours?: (number | null) | undefined, discount_percent?: (number | null) | undefined, bonus_amount_kopeks?: (number | null) | undefined, active_discount_hours?: (number | null) | undefined, test_duration_hours?: (number | null) | undefined, test_squad_uuids?: (Array | null) | undefined, is_active?: (boolean | null) | undefined}; export type PatchApiCabinetAdminPromoOffersTemplatesTemplateIdArgs = {template_id: number, body: PromoOfferTemplateUpdateRequest}; export type PatchApiCabinetAdminPromoOffersTemplatesTemplateIdOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const appCabinetRoutesAdminPromoOffersPromoOfferTemplateResponse = z.object({id: z.number().int(), name: z.string(), offer_type: z.string(), message_text: z.string(), button_text: z.string(), valid_hours: z.number().int(), discount_percent: z.number().int(), bonus_amount_kopeks: z.number().int(), active_discount_hours: z.number().int().nullable().optional(), test_duration_hours: z.number().int().nullable().optional(), test_squad_uuids: z.array(z.string()).optional(), is_active: z.boolean(), created_by: z.number().int().nullable().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 Template * * PATCH /cabinet/admin/promo-offers/templates/{template_id} */ export const patchApiCabinetAdminPromoOffersTemplatesTemplateId = async (args: PatchApiCabinetAdminPromoOffersTemplatesTemplateIdArgs, options: PatchApiCabinetAdminPromoOffersTemplatesTemplateIdOptions) => { 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/promo-offers/templates/${encodeURIComponent(String(args.template_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(appCabinetRoutesAdminPromoOffersPromoOfferTemplateResponse, await res.json()) };