import {z} from 'zod' export type GoogleAdsSearchads360V23CommonAdScheduleInfo = {dayOfWeek?: ('UNSPECIFIED' | 'UNKNOWN' | 'MONDAY' | 'TUESDAY' | 'WEDNESDAY' | 'THURSDAY' | 'FRIDAY' | 'SATURDAY' | 'SUNDAY') | undefined, endHour?: number | undefined, endMinute?: ('UNSPECIFIED' | 'UNKNOWN' | 'ZERO' | 'FIFTEEN' | 'THIRTY' | 'FORTY_FIVE') | undefined, startHour?: number | undefined, startMinute?: ('UNSPECIFIED' | 'UNKNOWN' | 'ZERO' | 'FIFTEEN' | 'THIRTY' | 'FORTY_FIVE') | undefined}; export type GoogleAdsSearchads360V23ServicesSmartCampaignSuggestionInfoBusinessContext = {businessName?: string | undefined}; export type GoogleAdsSearchads360V23CommonKeywordThemeInfo = {freeFormKeywordTheme?: string | undefined, keywordThemeConstant?: string | undefined}; export type GoogleAdsSearchads360V23CommonLocationInfo = {geoTargetConstant?: string | undefined}; export type GoogleAdsSearchads360V23ServicesSmartCampaignSuggestionInfoLocationList = {locations?: Array | undefined}; export type GoogleAdsSearchads360V23CommonAddressInfo = {cityName?: string | undefined, countryCode?: string | undefined, postalCode?: string | undefined, provinceCode?: string | undefined, provinceName?: string | undefined, streetAddress?: string | undefined, streetAddress2?: string | undefined}; export type GoogleAdsSearchads360V23CommonGeoPointInfo = {latitudeInMicroDegrees?: number | undefined, longitudeInMicroDegrees?: number | undefined}; export type GoogleAdsSearchads360V23CommonProximityInfo = {address?: GoogleAdsSearchads360V23CommonAddressInfo | undefined, geoPoint?: GoogleAdsSearchads360V23CommonGeoPointInfo | undefined, radius?: number | undefined, radiusUnits?: ('UNSPECIFIED' | 'UNKNOWN' | 'MILES' | 'KILOMETERS') | undefined}; export type GoogleAdsSearchads360V23ServicesSmartCampaignSuggestionInfo = {adSchedules?: Array | undefined, businessContext?: GoogleAdsSearchads360V23ServicesSmartCampaignSuggestionInfoBusinessContext | undefined, businessProfileLocation?: string | undefined, finalUrl?: string | undefined, keywordThemes?: Array | undefined, languageCode?: string | undefined, locationList?: GoogleAdsSearchads360V23ServicesSmartCampaignSuggestionInfoLocationList | undefined, proximity?: GoogleAdsSearchads360V23CommonProximityInfo | undefined}; export type GoogleAdsSearchads360V23ServicesSuggestSmartCampaignBudgetOptionsRequest = {campaign?: string | undefined, suggestionInfo?: GoogleAdsSearchads360V23ServicesSmartCampaignSuggestionInfo | undefined}; export type CreateApiV23CustomersCustomersIdSuggestSmartCampaignBudgetOptionsArgs = {customersId: string, body: GoogleAdsSearchads360V23ServicesSuggestSmartCampaignBudgetOptionsRequest}; export type CreateApiV23CustomersCustomersIdSuggestSmartCampaignBudgetOptionsOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const googleAdsSearchads360V23ServicesSuggestSmartCampaignBudgetOptionsResponseMetrics = z.object({maxDailyClicks: z.string().optional(), minDailyClicks: z.string().optional()}); export const googleAdsSearchads360V23ServicesSuggestSmartCampaignBudgetOptionsResponseBudgetOption = z.object({dailyAmountMicros: z.string().optional(), metrics: googleAdsSearchads360V23ServicesSuggestSmartCampaignBudgetOptionsResponseMetrics.optional()}); export const googleAdsSearchads360V23ServicesSuggestSmartCampaignBudgetOptionsResponse = z.object({high: googleAdsSearchads360V23ServicesSuggestSmartCampaignBudgetOptionsResponseBudgetOption.optional(), low: googleAdsSearchads360V23ServicesSuggestSmartCampaignBudgetOptionsResponseBudgetOption.optional(), recommended: googleAdsSearchads360V23ServicesSuggestSmartCampaignBudgetOptionsResponseBudgetOption.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 }; /** * Returns BudgetOption suggestions. * * POST /v23/customers/{customersId}:suggestSmartCampaignBudgetOptions */ export const createApiV23CustomersCustomersIdSuggestSmartCampaignBudgetOptions = async (args: CreateApiV23CustomersCustomersIdSuggestSmartCampaignBudgetOptionsArgs, options?: CreateApiV23CustomersCustomersIdSuggestSmartCampaignBudgetOptionsOptions) => { const {baseUrl = "https://searchads360.googleapis.com", fetch: fetchFn = fetch, Oauth2, Oauth2c} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Oauth2 !== undefined) headers.set('authorization', `Bearer ${Oauth2}`) if (Oauth2c !== undefined) headers.set('authorization', `Bearer ${Oauth2c}`) const url = `${baseUrl.replace(/\/+$/, '')}/v23/customers/${encodeURIComponent(String(args.customersId))}:suggestSmartCampaignBudgetOptions${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(googleAdsSearchads360V23ServicesSuggestSmartCampaignBudgetOptionsResponse, await res.json()) };