Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

66.6 KB
Raw Blame
import { apiMutator } from '../../../../frontend/src/lib/api-orval-mutator'
/**
 * Auto-generated from the Django backend OpenAPI schema.
 * To modify these types, update the Django serializers or views, then run:
 *   hogli build:openapi
 * Questions or issues? #team-devex on Slack
 *
 * PostHog API - generated
 * OpenAPI spec version: 1.0.0
 */
import type {
    AEOPromptApi,
    AEOPromptBulkImportRequestApi,
    AEOPromptImportResultApi,
    AEOPromptSetOverviewApi,
    AEOPromptStatsApi,
    AEOPromptSuggestRequestApi,
    AEOPromptSuggestionJobApi,
    AEOPromptTopicApi,
    AEOPromptVersionApi,
    AchievementsListResponseApi,
    AcknowledgeCelebrationRequestApi,
    AcknowledgeCelebrationResponseApi,
    AeoPromptsChecksParams,
    AeoPromptsListParams,
    AeoPromptsOverviewParams,
    ApplyPathCleaningSuggestionResponseApi,
    ContentAutopilotExportResponseApi,
    ContentAutopilotOpportunityApi,
    ContentAutopilotOpportunityDraftRequestApi,
    ContentAutopilotOpportunityRefreshRequestApi,
    ContentAutopilotProposalApi,
    ContentAutopilotProposalEditRequestApi,
    ContentAutopilotRunApi,
    ContentAutopilotRunStartRequestApi,
    ContentAutopilotSiteDiscoveryRequestApi,
    ContentAutopilotSiteDiscoveryResponseApi,
    ContentAutopilotSiteProfileApi,
    GeneratePathCleaningSuggestionResponseApi,
    HeatmapCapturePagesApi,
    HeatmapCaptureRequestApi,
    HeatmapCaptureSettingsApi,
    HeatmapEventsResponseApi,
    HeatmapPreflightRequestApi,
    HeatmapPreflightResponseApi,
    HeatmapPrewarmRequestApi,
    HeatmapScreenshotHistoryCaptureResponseApi,
    HeatmapScreenshotHistoryResponseApi,
    HeatmapScreenshotResponseApi,
    HeatmapScreenshotSettingsApi,
    HeatmapScreenshotsContentRetrieveParams,
    HeatmapsEventsRetrieveParams,
    HeatmapsListParams,
    HeatmapsResponseApi,
    LlmsTxtFetchRequestApi,
    LlmsTxtFetchResponseApi,
    PaginatedAEOPromptCheckListApi,
    PaginatedAEOPromptListApi,
    PaginatedContentAutopilotOpportunityListApi,
    PaginatedContentAutopilotProposalListListApi,
    PaginatedContentAutopilotRunListApi,
    PaginatedContentAutopilotSiteProfileListApi,
    PaginatedWebAnalyticsFilterPresetListApi,
    PatchedAEOPromptUpdateRequestApi,
    PatchedContentAutopilotSiteProfileApi,
    PatchedHeatmapCaptureSettingsRequestApi,
    PatchedHeatmapScreenshotSettingsRequestApi,
    PatchedSavedHeatmapRequestApi,
    PatchedWebAnalyticsFilterPresetApi,
    PreviewPathCleaningSuggestionResponseApi,
    RecordInteractionRequestApi,
    RecordInteractionResponseApi,
    RecordVisitResponseApi,
    SavedHeatmapCaptureRequestApi,
    SavedHeatmapListResponseApi,
    SavedHeatmapRequestApi,
    SavedListParams,
    SavedScreenshotHistoryContentRetrieveParams,
    WebAnalyticsBotRuleApi,
    WebAnalyticsContentAutopilotOpportunitiesListParams,
    WebAnalyticsContentAutopilotProfilesListParams,
    WebAnalyticsContentAutopilotProposalsListParams,
    WebAnalyticsContentAutopilotRunsListParams,
    WebAnalyticsFilterPresetApi,
    WebAnalyticsFilterPresetsListParams,
    WebAnalyticsRecapParams,
    WebAnalyticsRecapResponseApi,
    WebAnalyticsUserPreferencesApi,
    WebAnalyticsWeeklyDigestParams,
    WeeklyDigestResponseApi,
} from './api.schemas'

// https://stackoverflow.com/questions/49579094/typescript-conditional-types-filter-out-readonly-properties-pick-only-requir/49579497#49579497
type IfEquals<X, Y, A = X, B = never> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? A : B

type WritableKeys<T> = {
    [P in keyof T]-?: IfEquals<{ [Q in P]: T[P] }, { -readonly [Q in P]: T[P] }, P>
}[keyof T]

type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never
type DistributeReadOnlyOverUnions<T> = T extends any ? NonReadonly<T> : never

type Writable<T> = Pick<T, WritableKeys<T>>
type NonReadonly<T> = [T] extends [UnionToIntersection<T>]
    ? {
          [P in keyof Writable<T>]: T[P] extends object ? NonReadonly<NonNullable<T[P]>> : T[P]
      }
    : DistributeReadOnlyOverUnions<T>

export const getAeoPromptsListUrl = (projectId: string, params?: AeoPromptsListParams) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/aeo_prompts/?${stringifiedParams}`
        : `/api/projects/${projectId}/aeo_prompts/`
}

/**
 * Lists the project's AEO prompt set, ordered by topic and then rank, one page at a time. Filter by topic, by on/off state, or to the prompts that need improvement. Archived prompts are left out unless include_archived is true. Each prompt carries its latest check per answer engine.
 * @summary List AEO prompts
 */
export const aeoPromptsList = async (
    projectId: string,
    params?: AeoPromptsListParams,
    options?: RequestInit
): Promise<PaginatedAEOPromptListApi> => {
    return apiMutator<PaginatedAEOPromptListApi>(getAeoPromptsListUrl(projectId, params), {
        ...options,
        method: 'GET',
    })
}

export const getAeoPromptsRetrieveUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/aeo_prompts/${id}/`
}

/**
 * Gets one prompt from the project's AEO prompt set, archived ones included, with its latest check per answer engine.
 * @summary Get an AEO prompt
 */
export const aeoPromptsRetrieve = async (
    projectId: string,
    id: string,
    options?: RequestInit
): Promise<AEOPromptApi> => {
    return apiMutator<AEOPromptApi>(getAeoPromptsRetrieveUrl(projectId, id), {
        ...options,
        method: 'GET',
    })
}

export const getAeoPromptsPartialUpdateUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/aeo_prompts/${id}/`
}

/**
 * Turns a prompt on or off, changes its topic, archives or restores it, or changes its text. A text change adds the next version and makes it current, and current_version moves back to an earlier one. The prompt keeps its id, and past checks are always kept.
 * @summary Update an AEO prompt
 */
export const aeoPromptsPartialUpdate = async (
    projectId: string,
    id: string,
    patchedAEOPromptUpdateRequestApi?: PatchedAEOPromptUpdateRequestApi,
    options?: RequestInit
): Promise<AEOPromptApi> => {
    return apiMutator<AEOPromptApi>(getAeoPromptsPartialUpdateUrl(projectId, id), {
        ...options,
        method: 'PATCH',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(patchedAEOPromptUpdateRequestApi),
    })
}

export const getAeoPromptsDestroyUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/aeo_prompts/${id}/`
}

/**
 * Archives a prompt: it is turned off and never runs again. Nothing is deleted, and its versions and checks are kept. Restore it with a PATCH of archived=false.
 * @summary Archive an AEO prompt
 */
export const aeoPromptsDestroy = async (projectId: string, id: string, options?: RequestInit): Promise<void> => {
    return apiMutator<void>(getAeoPromptsDestroyUrl(projectId, id), {
        ...options,
        method: 'DELETE',
    })
}

export const getAeoPromptsChecksUrl = (projectId: string, id: string, params?: AeoPromptsChecksParams) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/aeo_prompts/${id}/checks/?${stringifiedParams}`
        : `/api/projects/${projectId}/aeo_prompts/${id}/checks/`
}

/**
 * Lists every check of one prompt, newest first, one page at a time. Filter by engine, by prompt version, or with since to see only checks from a point in time on. Each check has the engine's answer, the URLs it cited, the searches it ran and the prompt version it ran. Set include_answer_text=false to leave the answers out and page through history with smaller responses.
 * @summary List an AEO prompt's checks
 */
export const aeoPromptsChecks = async (
    projectId: string,
    id: string,
    params?: AeoPromptsChecksParams,
    options?: RequestInit
): Promise<PaginatedAEOPromptCheckListApi> => {
    return apiMutator<PaginatedAEOPromptCheckListApi>(getAeoPromptsChecksUrl(projectId, id, params), {
        ...options,
        method: 'GET',
    })
}

export const getAeoPromptsStatsUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/aeo_prompts/${id}/stats/`
}

/**
 * Gets citation and brand-mention totals per answer engine for one prompt, plus, for the last 30 days in the project's timezone, per-day counts, which engines cite which domains, brand sentiment per engine, and the words of the web searches the engines ran.
 * @summary Get an AEO prompt's citation stats
 */
export const aeoPromptsStats = async (
    projectId: string,
    id: string,
    options?: RequestInit
): Promise<AEOPromptStatsApi> => {
    return apiMutator<AEOPromptStatsApi>(getAeoPromptsStatsUrl(projectId, id), {
        ...options,
        method: 'GET',
    })
}

export const getAeoPromptsVersionsUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/aeo_prompts/${id}/versions/`
}

/**
 * Lists every version of a prompt's text, newest first. A text edit adds a version, and one of them is current.
 * @summary List an AEO prompt's versions
 */
export const aeoPromptsVersions = async (
    projectId: string,
    id: string,
    options?: RequestInit
): Promise<AEOPromptVersionApi[]> => {
    return apiMutator<AEOPromptVersionApi[]>(getAeoPromptsVersionsUrl(projectId, id), {
        ...options,
        method: 'GET',
    })
}

export const getAeoPromptsBulkImportUrl = (projectId: string) => {
    return `/api/projects/${projectId}/aeo_prompts/bulk_import/`
}

/**
 * Adds prompts to the project's AEO prompt set, or updates the topic and visibility of prompts that already exist. Existing prompts keep their active state. Prompts whose text matches an archived prompt are skipped.
 * @summary Import AEO prompts
 */
export const aeoPromptsBulkImport = async (
    projectId: string,
    aEOPromptBulkImportRequestApi: AEOPromptBulkImportRequestApi,
    options?: RequestInit
): Promise<AEOPromptImportResultApi> => {
    return apiMutator<AEOPromptImportResultApi>(getAeoPromptsBulkImportUrl(projectId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(aEOPromptBulkImportRequestApi),
    })
}

export const getAeoPromptsOverviewUrl = (projectId: string, params?: AeoPromptsOverviewParams) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/aeo_prompts/overview/?${stringifiedParams}`
        : `/api/projects/${projectId}/aeo_prompts/overview/`
}

/**
 * Gets an overview of the project's whole AEO prompt set for the last 'days' days (default 30) in the project's timezone: how many prompts are tracked, how many checks ran, the citation rate and the brand-mention rate, the same counts for the window before it, the current window split per answer engine (Claude, ChatGPT/OpenAI, Exa) and per topic, and the domains the engines cited most.
 * @summary Get the AEO prompt set overview
 */
export const aeoPromptsOverview = async (
    projectId: string,
    params?: AeoPromptsOverviewParams,
    options?: RequestInit
): Promise<AEOPromptSetOverviewApi> => {
    return apiMutator<AEOPromptSetOverviewApi>(getAeoPromptsOverviewUrl(projectId, params), {
        ...options,
        method: 'GET',
    })
}

export const getAeoPromptsSuggestUrl = (projectId: string) => {
    return `/api/projects/${projectId}/aeo_prompts/suggest/`
}

/**
 * Suggests prompts to track for a site. Requires AI data processing approved for the organization. Claude reads the site with web search and writes questions a buyer would ask an AI assistant, each labeled with a topic, a circle, a funnel stage and whether it names the brand. Nothing is saved: import the prompts you keep with bulk_import. Prompts the project already tracks are left out. Returns a pending job right away; poll GET aeo_prompts/suggest/<id>/ until it completes, which takes up to a few minutes.
 * @summary Suggest AEO prompts
 */
export const aeoPromptsSuggest = async (
    projectId: string,
    aEOPromptSuggestRequestApi: AEOPromptSuggestRequestApi,
    options?: RequestInit
): Promise<AEOPromptSuggestionJobApi> => {
    return apiMutator<AEOPromptSuggestionJobApi>(getAeoPromptsSuggestUrl(projectId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(aEOPromptSuggestRequestApi),
    })
}

export const getAeoPromptsSuggestionRetrieveUrl = (projectId: string, jobId: string) => {
    return `/api/projects/${projectId}/aeo_prompts/suggest/${jobId}/`
}

/**
 * Gets a prompt suggestion job started with POST aeo_prompts/suggest/. status is pending while Claude works, then completed with the suggestions or failed with an error. Jobs expire an hour after their last update.
 * @summary Get AEO prompt suggestions
 */
export const aeoPromptsSuggestionRetrieve = async (
    projectId: string,
    jobId: string,
    options?: RequestInit
): Promise<AEOPromptSuggestionJobApi> => {
    return apiMutator<AEOPromptSuggestionJobApi>(getAeoPromptsSuggestionRetrieveUrl(projectId, jobId), {
        ...options,
        method: 'GET',
    })
}

export const getAeoPromptsTopicsUrl = (projectId: string) => {
    return `/api/projects/${projectId}/aeo_prompts/topics/`
}

/**
 * Lists the topics in the project's AEO prompt set, with the number of prompts in each.
 * @summary List AEO prompt topics
 */
export const aeoPromptsTopics = async (projectId: string, options?: RequestInit): Promise<AEOPromptTopicApi[]> => {
    return apiMutator<AEOPromptTopicApi[]>(getAeoPromptsTopicsUrl(projectId), {
        ...options,
        method: 'GET',
    })
}

export const getHeatmapCapturePagesRetrieveUrl = (projectId: string) => {
    return `/api/projects/${projectId}/heatmap_capture/pages/`
}

export const heatmapCapturePagesRetrieve = async (
    projectId: string,
    options?: RequestInit
): Promise<HeatmapCapturePagesApi> => {
    return apiMutator<HeatmapCapturePagesApi>(getHeatmapCapturePagesRetrieveUrl(projectId), {
        ...options,
        method: 'GET',
    })
}

export const getHeatmapCaptureSettingsRetrieveUrl = (projectId: string) => {
    return `/api/projects/${projectId}/heatmap_capture/settings/`
}

export const heatmapCaptureSettingsRetrieve = async (
    projectId: string,
    options?: RequestInit
): Promise<HeatmapCaptureSettingsApi> => {
    return apiMutator<HeatmapCaptureSettingsApi>(getHeatmapCaptureSettingsRetrieveUrl(projectId), {
        ...options,
        method: 'GET',
    })
}

export const getHeatmapCaptureSettingsUpdateUrl = (projectId: string) => {
    return `/api/projects/${projectId}/heatmap_capture/settings/`
}

export const heatmapCaptureSettingsUpdate = async (
    projectId: string,
    patchedHeatmapCaptureSettingsRequestApi?: PatchedHeatmapCaptureSettingsRequestApi,
    options?: RequestInit
): Promise<HeatmapCaptureSettingsApi> => {
    return apiMutator<HeatmapCaptureSettingsApi>(getHeatmapCaptureSettingsUpdateUrl(projectId), {
        ...options,
        method: 'PATCH',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(patchedHeatmapCaptureSettingsRequestApi),
    })
}

export const getHeatmapScreenshotSettingsRetrieveUrl = (projectId: string) => {
    return `/api/projects/${projectId}/heatmap_screenshot/settings/`
}

export const heatmapScreenshotSettingsRetrieve = async (
    projectId: string,
    options?: RequestInit
): Promise<HeatmapScreenshotSettingsApi> => {
    return apiMutator<HeatmapScreenshotSettingsApi>(getHeatmapScreenshotSettingsRetrieveUrl(projectId), {
        ...options,
        method: 'GET',
    })
}

export const getHeatmapScreenshotSettingsUpdateUrl = (projectId: string) => {
    return `/api/projects/${projectId}/heatmap_screenshot/settings/`
}

export const heatmapScreenshotSettingsUpdate = async (
    projectId: string,
    patchedHeatmapScreenshotSettingsRequestApi?: PatchedHeatmapScreenshotSettingsRequestApi,
    options?: RequestInit
): Promise<HeatmapScreenshotSettingsApi> => {
    return apiMutator<HeatmapScreenshotSettingsApi>(getHeatmapScreenshotSettingsUpdateUrl(projectId), {
        ...options,
        method: 'PATCH',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(patchedHeatmapScreenshotSettingsRequestApi),
    })
}

export const getHeatmapScreenshotsContentRetrieveUrl = (
    projectId: string,
    id: string,
    params?: HeatmapScreenshotsContentRetrieveParams
) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/heatmap_screenshots/${id}/content/?${stringifiedParams}`
        : `/api/projects/${projectId}/heatmap_screenshots/${id}/content/`
}

/**
 * Fetch the rendered screenshot image (JPEG bytes) for a saved heatmap at a given viewport width. Returns 202 with the saved-heatmap metadata while the screenshot is still being generated.
 */
export const heatmapScreenshotsContentRetrieve = async (
    projectId: string,
    id: string,
    params?: HeatmapScreenshotsContentRetrieveParams,
    options?: RequestInit
): Promise<Blob | HeatmapScreenshotResponseApi> => {
    return apiMutator<Blob | HeatmapScreenshotResponseApi>(
        getHeatmapScreenshotsContentRetrieveUrl(projectId, id, params),
        {
            ...options,
            method: 'GET',
        }
    )
}

export const getHeatmapsListUrl = (projectId: string, params?: HeatmapsListParams) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/heatmaps/?${stringifiedParams}`
        : `/api/projects/${projectId}/heatmaps/`
}

/**
 * Aggregated heatmap interactions for a page. For type 'click'/'rageclick'/'mousemove' each result is a point with relative x, absolute client-y, and a count. For type 'scrolldepth' the response is scroll-depth buckets instead (cumulative reach down the page).
 */
export const heatmapsList = async (
    projectId: string,
    params?: HeatmapsListParams,
    options?: RequestInit
): Promise<HeatmapsResponseApi[]> => {
    return apiMutator<HeatmapsResponseApi[]>(getHeatmapsListUrl(projectId, params), {
        ...options,
        method: 'GET',
    })
}

export const getHeatmapsEventsRetrieveUrl = (projectId: string, params: HeatmapsEventsRetrieveParams) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/heatmaps/events/?${stringifiedParams}`
        : `/api/projects/${projectId}/heatmaps/events/`
}

/**
 * Drill into the individual session interactions behind one or more heatmap coordinates. Pass the 'points' you want to inspect (from the heatmaps list response) to get the underlying per-session events, so you can jump to the session recordings that produced a hotspot.
 */
export const heatmapsEventsRetrieve = async (
    projectId: string,
    params: HeatmapsEventsRetrieveParams,
    options?: RequestInit
): Promise<HeatmapEventsResponseApi> => {
    return apiMutator<HeatmapEventsResponseApi>(getHeatmapsEventsRetrieveUrl(projectId, params), {
        ...options,
        method: 'GET',
    })
}

export const getSavedListUrl = (projectId: string, params?: SavedListParams) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/saved/?${stringifiedParams}`
        : `/api/projects/${projectId}/saved/`
}

/**
 * List saved heatmaps for the project. A saved heatmap pins a page URL and a set of viewport widths, and (for type 'screenshot') renders the page so heatmap data can be overlaid on it.
 */
export const savedList = async (
    projectId: string,
    params?: SavedListParams,
    options?: RequestInit
): Promise<SavedHeatmapListResponseApi[]> => {
    return apiMutator<SavedHeatmapListResponseApi[]>(getSavedListUrl(projectId, params), {
        ...options,
        method: 'GET',
    })
}

export const getSavedCreateUrl = (projectId: string) => {
    return `/api/projects/${projectId}/saved/`
}

/**
 * Create a saved heatmap for a page URL. For type 'screenshot' (the default) this enqueues a headless render of the page at each target width; poll the saved heatmap or its content endpoint until status is 'completed'. Provide 'widths' to control which viewport widths are rendered.
 */
export const savedCreate = async (
    projectId: string,
    savedHeatmapRequestApi: SavedHeatmapRequestApi,
    options?: RequestInit
): Promise<HeatmapScreenshotResponseApi> => {
    return apiMutator<HeatmapScreenshotResponseApi>(getSavedCreateUrl(projectId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(savedHeatmapRequestApi),
    })
}

export const getSavedRetrieveUrl = (projectId: string, shortId: string) => {
    return `/api/projects/${projectId}/saved/${shortId}/`
}

/**
 * Get a single saved heatmap by its short_id, including per-width render status.
 */
export const savedRetrieve = async (
    projectId: string,
    shortId: string,
    options?: RequestInit
): Promise<HeatmapScreenshotResponseApi> => {
    return apiMutator<HeatmapScreenshotResponseApi>(getSavedRetrieveUrl(projectId, shortId), {
        ...options,
        method: 'GET',
    })
}

export const getSavedPartialUpdateUrl = (projectId: string, shortId: string) => {
    return `/api/projects/${projectId}/saved/${shortId}/`
}

/**
 * Update a saved heatmap (e.g. rename, change widths, or soft-delete via 'deleted'). Changing the URL of a 'screenshot' heatmap triggers a re-render.
 */
export const savedPartialUpdate = async (
    projectId: string,
    shortId: string,
    patchedSavedHeatmapRequestApi?: PatchedSavedHeatmapRequestApi,
    options?: RequestInit
): Promise<HeatmapScreenshotResponseApi> => {
    return apiMutator<HeatmapScreenshotResponseApi>(getSavedPartialUpdateUrl(projectId, shortId), {
        ...options,
        method: 'PATCH',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(patchedSavedHeatmapRequestApi),
    })
}

export const getSavedDestroyUrl = (projectId: string, shortId: string) => {
    return `/api/projects/${projectId}/saved/${shortId}/`
}

/**
 * Hard delete of this model is not allowed. Use a patch API call to set "deleted" to true
 */
export const savedDestroy = async (projectId: string, shortId: string, options?: RequestInit): Promise<unknown> => {
    return apiMutator<unknown>(getSavedDestroyUrl(projectId, shortId), {
        ...options,
        method: 'DELETE',
    })
}

export const getSavedRegenerateCreateUrl = (projectId: string, shortId: string) => {
    return `/api/projects/${projectId}/saved/${shortId}/regenerate/`
}

/**
 * Re-run screenshot generation for a saved heatmap of type 'screenshot'. Clears existing renders and re-renders at every target width; status returns to 'processing'.
 */
export const savedRegenerateCreate = async (
    projectId: string,
    shortId: string,
    options?: RequestInit
): Promise<HeatmapScreenshotResponseApi> => {
    return apiMutator<HeatmapScreenshotResponseApi>(getSavedRegenerateCreateUrl(projectId, shortId), {
        ...options,
        method: 'POST',
    })
}

export const getSavedScreenshotHistoryRetrieveUrl = (projectId: string, shortId: string) => {
    return `/api/projects/${projectId}/saved/${shortId}/screenshot_history/`
}

/**
 * List the daily screenshot captures kept for a saved heatmap, newest first. Each capture is a render of the page on that day at one viewport width, so the clicks of a day or a range can be viewed over the background that matches it. Captures older than the retention window are deleted.
 */
export const savedScreenshotHistoryRetrieve = async (
    projectId: string,
    shortId: string,
    options?: RequestInit
): Promise<HeatmapScreenshotHistoryResponseApi> => {
    return apiMutator<HeatmapScreenshotHistoryResponseApi>(getSavedScreenshotHistoryRetrieveUrl(projectId, shortId), {
        ...options,
        method: 'GET',
    })
}

export const getSavedScreenshotHistoryContentRetrieveUrl = (
    projectId: string,
    shortId: string,
    historyId: string,
    params: SavedScreenshotHistoryContentRetrieveParams
) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/saved/${shortId}/screenshot_history/${historyId}/content/?${stringifiedParams}`
        : `/api/projects/${projectId}/saved/${shortId}/screenshot_history/${historyId}/content/`
}

/**
 * Fetch the JPEG for one daily capture, or its thumbnail. The list endpoint hands out versioned URLs, so the response carries a private day-long cache lifetime and an ETag that changes when the day is captured again.
 */
export const savedScreenshotHistoryContentRetrieve = async (
    projectId: string,
    shortId: string,
    historyId: string,
    params: SavedScreenshotHistoryContentRetrieveParams,
    options?: RequestInit
): Promise<Blob> => {
    return apiMutator<Blob>(getSavedScreenshotHistoryContentRetrieveUrl(projectId, shortId, historyId, params), {
        ...options,
        method: 'GET',
    })
}

export const getSavedScreenshotHistoryCaptureCreateUrl = (projectId: string, shortId: string) => {
    return `/api/projects/${projectId}/saved/${shortId}/screenshot_history/capture/`
}

/**
 * Render and keep a capture of the page now, instead of waiting for the daily run, for example right after a deploy. The render runs in the background; poll the history list for the new capture. A capture requested on a day that already has one replaces that day's image.
 */
export const savedScreenshotHistoryCaptureCreate = async (
    projectId: string,
    shortId: string,
    options?: RequestInit
): Promise<HeatmapScreenshotHistoryCaptureResponseApi> => {
    return apiMutator<HeatmapScreenshotHistoryCaptureResponseApi>(
        getSavedScreenshotHistoryCaptureCreateUrl(projectId, shortId),
        {
            ...options,
            method: 'POST',
        }
    )
}

export const getSavedScreenshotHistoryRequestsRetrieveUrl = (projectId: string, shortId: string, requestId: string) => {
    return `/api/projects/${projectId}/saved/${shortId}/screenshot_history/requests/${requestId}/`
}

/**
 * Read the outcome of a capture request.
 */
export const savedScreenshotHistoryRequestsRetrieve = async (
    projectId: string,
    shortId: string,
    requestId: string,
    options?: RequestInit
): Promise<HeatmapCaptureRequestApi> => {
    return apiMutator<HeatmapCaptureRequestApi>(
        getSavedScreenshotHistoryRequestsRetrieveUrl(projectId, shortId, requestId),
        {
            ...options,
            method: 'GET',
        }
    )
}

export const getSavedCaptureCreateUrl = (projectId: string) => {
    return `/api/projects/${projectId}/saved/capture/`
}

/**
 * Persist screenshots captured client-side by the on-page toolbar as a completed screenshot heatmap. No headless render is enqueued: the toolbar runs in the user's authenticated browser, so this is the path for pages behind a login that Browserless cannot reach. Send one 'image'+'width', or 'images'+'widths' parallel arrays to store several viewport widths on one heatmap (the toolbar re-lays out the page at each width and captures it, matching the widths the server renders). The image bytes are stored and served only through the authenticated content endpoint. The optional data URL selects which pages supply the overlay data and defaults to the captured URL.
 */
export const savedCaptureCreate = async (
    projectId: string,
    savedHeatmapCaptureRequestApi: SavedHeatmapCaptureRequestApi,
    options?: RequestInit
): Promise<HeatmapScreenshotResponseApi> => {
    const formData = new FormData()
    if (savedHeatmapCaptureRequestApi.image !== undefined && savedHeatmapCaptureRequestApi.image !== null) {
        formData.append(`image`, savedHeatmapCaptureRequestApi.image)
    }
    if (savedHeatmapCaptureRequestApi.width !== undefined) {
        formData.append(`width`, savedHeatmapCaptureRequestApi.width.toString())
    }
    if (savedHeatmapCaptureRequestApi.images !== undefined) {
        savedHeatmapCaptureRequestApi.images.forEach((value) => formData.append(`images`, value))
    }
    if (savedHeatmapCaptureRequestApi.widths !== undefined) {
        savedHeatmapCaptureRequestApi.widths.forEach((value) => formData.append(`widths`, value.toString()))
    }
    formData.append(`url`, savedHeatmapCaptureRequestApi.url)
    if (savedHeatmapCaptureRequestApi.data_url !== undefined) {
        formData.append(`data_url`, savedHeatmapCaptureRequestApi.data_url)
    }
    if (savedHeatmapCaptureRequestApi.name !== undefined) {
        formData.append(`name`, savedHeatmapCaptureRequestApi.name)
    }

    return apiMutator<HeatmapScreenshotResponseApi>(getSavedCaptureCreateUrl(projectId), {
        ...options,
        method: 'POST',
        body: formData,
    })
}

export const getSavedPreflightCreateUrl = (projectId: string) => {
    return `/api/projects/${projectId}/saved/preflight/`
}

/**
 * Fetch a page URL server-side and report whether it allows being embedded in the live preview iframe, plus the HTTP status it returned. The live preview loads the customer's site directly in their browser, so a site that sends X-Frame-Options or a restrictive frame-ancestors will never render, and a 4xx or 5xx from the site's own host or CDN leaves an empty frame with no explanation. This endpoint makes both cases explainable. The fetch comes from PostHog's own network rather than from the screenshot renderer, so a host that varies its response by IP or user agent can answer this differently than it answers a screenshot render. Settled verdicts are cached briefly, so repeat checks for the same URL do not refetch it.
 * @summary Check whether a page can back a heatmap
 */
export const savedPreflightCreate = async (
    projectId: string,
    heatmapPreflightRequestApi: HeatmapPreflightRequestApi,
    options?: RequestInit
): Promise<HeatmapPreflightResponseApi> => {
    return apiMutator<HeatmapPreflightResponseApi>(getSavedPreflightCreateUrl(projectId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(heatmapPreflightRequestApi),
    })
}

export const getSavedPrewarmCreateUrl = (projectId: string) => {
    return `/api/projects/${projectId}/saved/prewarm/`
}

/**
 * Speculatively render a screenshot for a page URL ahead of heatmap creation, so it's ready (or closer to ready) by the time the user reaches the generation screen. Renders a single preview width. Idempotent within a short window: returns the existing in-flight or completed prewarm render for the same URL and consent setting if one exists (200), otherwise starts a new one (201). The result is reused when a heatmap is later created for the same URL.
 */
export const savedPrewarmCreate = async (
    projectId: string,
    heatmapPrewarmRequestApi: HeatmapPrewarmRequestApi,
    options?: RequestInit
): Promise<HeatmapScreenshotResponseApi> => {
    return apiMutator<HeatmapScreenshotResponseApi>(getSavedPrewarmCreateUrl(projectId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(heatmapPrewarmRequestApi),
    })
}

export const getWebAnalyticsFetchLlmsTxtUrl = (projectId: string) => {
    return `/api/projects/${projectId}/web_analytics/llms_txt/`
}

/**
 * Loads an llms.txt file from a public URL for coverage analysis without saving it.
 * @summary Load an llms.txt file
 */
export const webAnalyticsFetchLlmsTxt = async (
    projectId: string,
    llmsTxtFetchRequestApi: LlmsTxtFetchRequestApi,
    options?: RequestInit
): Promise<LlmsTxtFetchResponseApi> => {
    return apiMutator<LlmsTxtFetchResponseApi>(getWebAnalyticsFetchLlmsTxtUrl(projectId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(llmsTxtFetchRequestApi),
    })
}

export const getWebAnalyticsRecapUrl = (projectId: string, params?: WebAnalyticsRecapParams) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/web_analytics/recap/?${stringifiedParams}`
        : `/api/projects/${projectId}/web_analytics/recap/`
}

/**
 * The 'Wrapped'-style weekly recap: everything in the weekly digest (visitors, pageviews, sessions, bounce rate, average session duration with period-over-period comparisons, top pages, top sources, and goals) plus a single derived weekly persona and a short list of screenshot-worthy highlights for the period.
 * @summary Weekly web analytics recap
 */
export const webAnalyticsRecap = async (
    projectId: string,
    params?: WebAnalyticsRecapParams,
    options?: RequestInit
): Promise<WebAnalyticsRecapResponseApi> => {
    return apiMutator<WebAnalyticsRecapResponseApi>(getWebAnalyticsRecapUrl(projectId, params), {
        ...options,
        method: 'GET',
    })
}

export const getWebAnalyticsWeeklyDigestUrl = (projectId: string, params?: WebAnalyticsWeeklyDigestParams) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/web_analytics/weekly_digest/?${stringifiedParams}`
        : `/api/projects/${projectId}/web_analytics/weekly_digest/`
}

/**
 * Summarizes a project's web analytics over a lookback window (default 7 days): unique visitors, pageviews, sessions, bounce rate, and average session duration with period-over-period comparisons, plus the top 5 pages, top 5 traffic sources, and goal conversions.
 * @summary Summarize web analytics
 */
export const webAnalyticsWeeklyDigest = async (
    projectId: string,
    params?: WebAnalyticsWeeklyDigestParams,
    options?: RequestInit
): Promise<WeeklyDigestResponseApi> => {
    return apiMutator<WeeklyDigestResponseApi>(getWebAnalyticsWeeklyDigestUrl(projectId, params), {
        ...options,
        method: 'GET',
    })
}

export const getWebAnalyticsAchievementsAcknowledgeCelebrationUrl = (projectId: string) => {
    return `/api/projects/${projectId}/web_analytics_achievements/acknowledge_celebration/`
}

/**
 * Clears a pending celebration for the given track and stage once the client has shown it, so it isn't celebrated again. Idempotent.
 * @summary Acknowledge an achievement celebration
 */
export const webAnalyticsAchievementsAcknowledgeCelebration = async (
    projectId: string,
    acknowledgeCelebrationRequestApi: AcknowledgeCelebrationRequestApi,
    options?: RequestInit
): Promise<AcknowledgeCelebrationResponseApi> => {
    return apiMutator<AcknowledgeCelebrationResponseApi>(
        getWebAnalyticsAchievementsAcknowledgeCelebrationUrl(projectId),
        {
            ...options,
            method: 'POST',
            headers: { 'Content-Type': 'application/json', ...options?.headers },
            body: JSON.stringify(acknowledgeCelebrationRequestApi),
        }
    )
}

export const getWebAnalyticsAchievementsOverviewUrl = (projectId: string) => {
    return `/api/projects/${projectId}/web_analytics_achievements/overview/`
}

/**
 * Returns the achievement track definitions (thresholds resolved for the requesting user's streak-cadence arm), the user's and team's progress, and any newly unlocked stages awaiting an in-session celebration.
 * @summary Get Web analytics achievements overview
 */
export const webAnalyticsAchievementsOverview = async (
    projectId: string,
    options?: RequestInit
): Promise<AchievementsListResponseApi> => {
    return apiMutator<AchievementsListResponseApi>(getWebAnalyticsAchievementsOverviewUrl(projectId), {
        ...options,
        method: 'GET',
    })
}

export const getWebAnalyticsAchievementsPreferencesUrl = (projectId: string) => {
    return `/api/projects/${projectId}/web_analytics_achievements/preferences/`
}

/**
 * Returns the requesting user's per-project Web analytics achievements preferences.
 * @summary Get Web analytics achievements preferences
 */
export const webAnalyticsAchievementsPreferences = async (
    projectId: string,
    options?: RequestInit
): Promise<WebAnalyticsUserPreferencesApi> => {
    return apiMutator<WebAnalyticsUserPreferencesApi>(getWebAnalyticsAchievementsPreferencesUrl(projectId), {
        ...options,
        method: 'GET',
    })
}

export const getWebAnalyticsAchievementsUpdatePreferencesUrl = (projectId: string) => {
    return `/api/projects/${projectId}/web_analytics_achievements/preferences/`
}

/**
 * Sets the requesting user's per-project Web analytics achievements preferences.
 * @summary Update Web analytics achievements preferences
 */
export const webAnalyticsAchievementsUpdatePreferences = async (
    projectId: string,
    webAnalyticsUserPreferencesApi: WebAnalyticsUserPreferencesApi,
    options?: RequestInit
): Promise<WebAnalyticsUserPreferencesApi> => {
    return apiMutator<WebAnalyticsUserPreferencesApi>(getWebAnalyticsAchievementsUpdatePreferencesUrl(projectId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(webAnalyticsUserPreferencesApi),
    })
}

export const getWebAnalyticsAchievementsRecordInteractionUrl = (projectId: string) => {
    return `/api/projects/${projectId}/web_analytics_achievements/record_interaction/`
}

/**
 * Idempotently increments the requesting user's first-party counter for an in-product Web analytics interaction (slicing data, or opening a session recording), which drives the Explorer and Detective achievement tracks.
 * @summary Record a Web analytics interaction
 */
export const webAnalyticsAchievementsRecordInteraction = async (
    projectId: string,
    recordInteractionRequestApi: RecordInteractionRequestApi,
    options?: RequestInit
): Promise<RecordInteractionResponseApi> => {
    return apiMutator<RecordInteractionResponseApi>(getWebAnalyticsAchievementsRecordInteractionUrl(projectId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(recordInteractionRequestApi),
    })
}

export const getWebAnalyticsAchievementsRecordVisitUrl = (projectId: string) => {
    return `/api/projects/${projectId}/web_analytics_achievements/record_visit/`
}

/**
 * Idempotently records that the requesting user opened Web analytics today (team-local date) and refreshes the user's per-user achievement tracks. Intended to be called once per session.
 * @summary Record a Web analytics visit
 */
export const webAnalyticsAchievementsRecordVisit = async (
    projectId: string,
    options?: RequestInit
): Promise<RecordVisitResponseApi> => {
    return apiMutator<RecordVisitResponseApi>(getWebAnalyticsAchievementsRecordVisitUrl(projectId), {
        ...options,
        method: 'POST',
    })
}

export const getWebAnalyticsBotRulesListUrl = (projectId: string) => {
    return `/api/projects/${projectId}/web_analytics_bot_rules/`
}

/**
 * The project's own bot rules, in the order they are checked at query time.
 * @summary List custom bot rules
 */
export const webAnalyticsBotRulesList = async (
    projectId: string,
    options?: RequestInit
): Promise<WebAnalyticsBotRuleApi[]> => {
    return apiMutator<WebAnalyticsBotRuleApi[]>(getWebAnalyticsBotRulesListUrl(projectId), {
        ...options,
        method: 'GET',
    })
}

export const getWebAnalyticsBotRulesCreateUrl = (projectId: string) => {
    return `/api/projects/${projectId}/web_analytics_bot_rules/`
}

/**
 * Add one bot rule to the project. A rule combines one or more single-property conditions with AND or OR. A pattern is rejected if it cannot run, because a broken rule would break every query that classifies traffic for the project.
 * @summary Create a custom bot rule
 */
export const webAnalyticsBotRulesCreate = async (
    projectId: string,
    webAnalyticsBotRuleApi: NonReadonly<WebAnalyticsBotRuleApi>,
    options?: RequestInit
): Promise<WebAnalyticsBotRuleApi> => {
    return apiMutator<WebAnalyticsBotRuleApi>(getWebAnalyticsBotRulesCreateUrl(projectId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(webAnalyticsBotRuleApi),
    })
}

export const getWebAnalyticsBotRulesDestroyUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/web_analytics_bot_rules/${id}/`
}

/**
 * Remove one bot rule by its id. The built-in bot list is unaffected.
 * @summary Delete a custom bot rule
 */
export const webAnalyticsBotRulesDestroy = async (
    projectId: string,
    id: string,
    options?: RequestInit
): Promise<void> => {
    return apiMutator<void>(getWebAnalyticsBotRulesDestroyUrl(projectId, id), {
        ...options,
        method: 'DELETE',
    })
}

export const getWebAnalyticsContentAutopilotOpportunitiesListUrl = (
    projectId: string,
    params: WebAnalyticsContentAutopilotOpportunitiesListParams
) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/web_analytics_content_autopilot_opportunities/?${stringifiedParams}`
        : `/api/projects/${projectId}/web_analytics_content_autopilot_opportunities/`
}

export const webAnalyticsContentAutopilotOpportunitiesList = async (
    projectId: string,
    params: WebAnalyticsContentAutopilotOpportunitiesListParams,
    options?: RequestInit
): Promise<PaginatedContentAutopilotOpportunityListApi> => {
    return apiMutator<PaginatedContentAutopilotOpportunityListApi>(
        getWebAnalyticsContentAutopilotOpportunitiesListUrl(projectId, params),
        {
            ...options,
            method: 'GET',
        }
    )
}

export const getWebAnalyticsContentAutopilotOpportunitiesRetrieveUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/web_analytics_content_autopilot_opportunities/${id}/`
}

export const webAnalyticsContentAutopilotOpportunitiesRetrieve = async (
    projectId: string,
    id: string,
    options?: RequestInit
): Promise<ContentAutopilotOpportunityApi> => {
    return apiMutator<ContentAutopilotOpportunityApi>(
        getWebAnalyticsContentAutopilotOpportunitiesRetrieveUrl(projectId, id),
        {
            ...options,
            method: 'GET',
        }
    )
}

export const getWebAnalyticsContentAutopilotOpportunitiesDismissUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/web_analytics_content_autopilot_opportunities/${id}/dismiss/`
}

/**
 * Marks an opportunity as dismissed. It stays dismissed across refreshes, and list responses still include it with status `dismissed`.
 * @summary Dismiss a content opportunity
 */
export const webAnalyticsContentAutopilotOpportunitiesDismiss = async (
    projectId: string,
    id: string,
    options?: RequestInit
): Promise<ContentAutopilotOpportunityApi> => {
    return apiMutator<ContentAutopilotOpportunityApi>(
        getWebAnalyticsContentAutopilotOpportunitiesDismissUrl(projectId, id),
        {
            ...options,
            method: 'POST',
        }
    )
}

export const getWebAnalyticsContentAutopilotOpportunitiesDraftUrl = (projectId: string) => {
    return `/api/projects/${projectId}/web_analytics_content_autopilot_opportunities/draft/`
}

/**
 * Starts a run that researches and drafts content for the selected opportunities.
 * @summary Draft content for opportunities
 */
export const webAnalyticsContentAutopilotOpportunitiesDraft = async (
    projectId: string,
    contentAutopilotOpportunityDraftRequestApi: ContentAutopilotOpportunityDraftRequestApi,
    options?: RequestInit
): Promise<ContentAutopilotRunApi> => {
    return apiMutator<ContentAutopilotRunApi>(getWebAnalyticsContentAutopilotOpportunitiesDraftUrl(projectId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(contentAutopilotOpportunityDraftRequestApi),
    })
}

export const getWebAnalyticsContentAutopilotOpportunitiesRefreshUrl = (projectId: string) => {
    return `/api/projects/${projectId}/web_analytics_content_autopilot_opportunities/refresh/`
}

/**
 * Re-reads AI citation checks and updates the site's content opportunities. Makes no model calls.
 * @summary Refresh content opportunities
 */
export const webAnalyticsContentAutopilotOpportunitiesRefresh = async (
    projectId: string,
    contentAutopilotOpportunityRefreshRequestApi: ContentAutopilotOpportunityRefreshRequestApi,
    options?: RequestInit
): Promise<ContentAutopilotOpportunityApi[]> => {
    return apiMutator<ContentAutopilotOpportunityApi[]>(
        getWebAnalyticsContentAutopilotOpportunitiesRefreshUrl(projectId),
        {
            ...options,
            method: 'POST',
            headers: { 'Content-Type': 'application/json', ...options?.headers },
            body: JSON.stringify(contentAutopilotOpportunityRefreshRequestApi),
        }
    )
}

export const getWebAnalyticsContentAutopilotProfilesListUrl = (
    projectId: string,
    params?: WebAnalyticsContentAutopilotProfilesListParams
) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/web_analytics_content_autopilot_profiles/?${stringifiedParams}`
        : `/api/projects/${projectId}/web_analytics_content_autopilot_profiles/`
}

export const webAnalyticsContentAutopilotProfilesList = async (
    projectId: string,
    params?: WebAnalyticsContentAutopilotProfilesListParams,
    options?: RequestInit
): Promise<PaginatedContentAutopilotSiteProfileListApi> => {
    return apiMutator<PaginatedContentAutopilotSiteProfileListApi>(
        getWebAnalyticsContentAutopilotProfilesListUrl(projectId, params),
        {
            ...options,
            method: 'GET',
        }
    )
}

export const getWebAnalyticsContentAutopilotProfilesCreateUrl = (projectId: string) => {
    return `/api/projects/${projectId}/web_analytics_content_autopilot_profiles/`
}

export const webAnalyticsContentAutopilotProfilesCreate = async (
    projectId: string,
    contentAutopilotSiteProfileApi: NonReadonly<ContentAutopilotSiteProfileApi>,
    options?: RequestInit
): Promise<ContentAutopilotSiteProfileApi> => {
    return apiMutator<ContentAutopilotSiteProfileApi>(getWebAnalyticsContentAutopilotProfilesCreateUrl(projectId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(contentAutopilotSiteProfileApi),
    })
}

export const getWebAnalyticsContentAutopilotProfilesRetrieveUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/web_analytics_content_autopilot_profiles/${id}/`
}

export const webAnalyticsContentAutopilotProfilesRetrieve = async (
    projectId: string,
    id: string,
    options?: RequestInit
): Promise<ContentAutopilotSiteProfileApi> => {
    return apiMutator<ContentAutopilotSiteProfileApi>(
        getWebAnalyticsContentAutopilotProfilesRetrieveUrl(projectId, id),
        {
            ...options,
            method: 'GET',
        }
    )
}

export const getWebAnalyticsContentAutopilotProfilesPartialUpdateUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/web_analytics_content_autopilot_profiles/${id}/`
}

export const webAnalyticsContentAutopilotProfilesPartialUpdate = async (
    projectId: string,
    id: string,
    patchedContentAutopilotSiteProfileApi?: NonReadonly<PatchedContentAutopilotSiteProfileApi>,
    options?: RequestInit
): Promise<ContentAutopilotSiteProfileApi> => {
    return apiMutator<ContentAutopilotSiteProfileApi>(
        getWebAnalyticsContentAutopilotProfilesPartialUpdateUrl(projectId, id),
        {
            ...options,
            method: 'PATCH',
            headers: { 'Content-Type': 'application/json', ...options?.headers },
            body: JSON.stringify(patchedContentAutopilotSiteProfileApi),
        }
    )
}

export const getWebAnalyticsContentAutopilotProfilesDestroyUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/web_analytics_content_autopilot_profiles/${id}/`
}

export const webAnalyticsContentAutopilotProfilesDestroy = async (
    projectId: string,
    id: string,
    options?: RequestInit
): Promise<void> => {
    return apiMutator<void>(getWebAnalyticsContentAutopilotProfilesDestroyUrl(projectId, id), {
        ...options,
        method: 'DELETE',
    })
}

export const getWebAnalyticsContentAutopilotProfilesDiscoverUrl = (projectId: string) => {
    return `/api/projects/${projectId}/web_analytics_content_autopilot_profiles/discover/`
}

/**
 * Inspects a public site for its canonical origin, name, and sitemap URLs.
 * @summary Discover content autopilot site settings
 */
export const webAnalyticsContentAutopilotProfilesDiscover = async (
    projectId: string,
    contentAutopilotSiteDiscoveryRequestApi: ContentAutopilotSiteDiscoveryRequestApi,
    options?: RequestInit
): Promise<ContentAutopilotSiteDiscoveryResponseApi> => {
    return apiMutator<ContentAutopilotSiteDiscoveryResponseApi>(
        getWebAnalyticsContentAutopilotProfilesDiscoverUrl(projectId),
        {
            ...options,
            method: 'POST',
            headers: { 'Content-Type': 'application/json', ...options?.headers },
            body: JSON.stringify(contentAutopilotSiteDiscoveryRequestApi),
        }
    )
}

export const getWebAnalyticsContentAutopilotProposalsListUrl = (
    projectId: string,
    params?: WebAnalyticsContentAutopilotProposalsListParams
) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/web_analytics_content_autopilot_proposals/?${stringifiedParams}`
        : `/api/projects/${projectId}/web_analytics_content_autopilot_proposals/`
}

export const webAnalyticsContentAutopilotProposalsList = async (
    projectId: string,
    params?: WebAnalyticsContentAutopilotProposalsListParams,
    options?: RequestInit
): Promise<PaginatedContentAutopilotProposalListListApi> => {
    return apiMutator<PaginatedContentAutopilotProposalListListApi>(
        getWebAnalyticsContentAutopilotProposalsListUrl(projectId, params),
        {
            ...options,
            method: 'GET',
        }
    )
}

export const getWebAnalyticsContentAutopilotProposalsRetrieveUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/web_analytics_content_autopilot_proposals/${id}/`
}

export const webAnalyticsContentAutopilotProposalsRetrieve = async (
    projectId: string,
    id: string,
    options?: RequestInit
): Promise<ContentAutopilotProposalApi> => {
    return apiMutator<ContentAutopilotProposalApi>(getWebAnalyticsContentAutopilotProposalsRetrieveUrl(projectId, id), {
        ...options,
        method: 'GET',
    })
}

export const getWebAnalyticsContentAutopilotProposalsEditUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/web_analytics_content_autopilot_proposals/${id}/edit/`
}

/**
 * Saves reviewed Markdown and its structured package without publishing it.
 * @summary Edit a content proposal
 */
export const webAnalyticsContentAutopilotProposalsEdit = async (
    projectId: string,
    id: string,
    contentAutopilotProposalEditRequestApi: ContentAutopilotProposalEditRequestApi,
    options?: RequestInit
): Promise<ContentAutopilotProposalApi> => {
    return apiMutator<ContentAutopilotProposalApi>(getWebAnalyticsContentAutopilotProposalsEditUrl(projectId, id), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(contentAutopilotProposalEditRequestApi),
    })
}

export const getWebAnalyticsContentAutopilotProposalsExportUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/web_analytics_content_autopilot_proposals/${id}/export/`
}

/**
 * Returns validated Markdown and structured JSON without publishing it.
 * @summary Export a content proposal
 */
export const webAnalyticsContentAutopilotProposalsExport = async (
    projectId: string,
    id: string,
    options?: RequestInit
): Promise<ContentAutopilotExportResponseApi> => {
    return apiMutator<ContentAutopilotExportResponseApi>(
        getWebAnalyticsContentAutopilotProposalsExportUrl(projectId, id),
        {
            ...options,
            method: 'POST',
        }
    )
}

export const getWebAnalyticsContentAutopilotProposalsRegenerateUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/web_analytics_content_autopilot_proposals/${id}/regenerate/`
}

/**
 * Returns a proposal to generation while keeping its previous result inspectable in history.
 * @summary Regenerate a content proposal
 */
export const webAnalyticsContentAutopilotProposalsRegenerate = async (
    projectId: string,
    id: string,
    options?: RequestInit
): Promise<ContentAutopilotProposalApi> => {
    return apiMutator<ContentAutopilotProposalApi>(
        getWebAnalyticsContentAutopilotProposalsRegenerateUrl(projectId, id),
        {
            ...options,
            method: 'POST',
        }
    )
}

export const getWebAnalyticsContentAutopilotProposalsRejectUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/web_analytics_content_autopilot_proposals/${id}/reject/`
}

/**
 * Rejects a proposal without changing the public site.
 * @summary Reject a content proposal
 */
export const webAnalyticsContentAutopilotProposalsReject = async (
    projectId: string,
    id: string,
    options?: RequestInit
): Promise<ContentAutopilotProposalApi> => {
    return apiMutator<ContentAutopilotProposalApi>(getWebAnalyticsContentAutopilotProposalsRejectUrl(projectId, id), {
        ...options,
        method: 'POST',
    })
}

export const getWebAnalyticsContentAutopilotRunsListUrl = (
    projectId: string,
    params?: WebAnalyticsContentAutopilotRunsListParams
) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/web_analytics_content_autopilot_runs/?${stringifiedParams}`
        : `/api/projects/${projectId}/web_analytics_content_autopilot_runs/`
}

export const webAnalyticsContentAutopilotRunsList = async (
    projectId: string,
    params?: WebAnalyticsContentAutopilotRunsListParams,
    options?: RequestInit
): Promise<PaginatedContentAutopilotRunListApi> => {
    return apiMutator<PaginatedContentAutopilotRunListApi>(
        getWebAnalyticsContentAutopilotRunsListUrl(projectId, params),
        {
            ...options,
            method: 'GET',
        }
    )
}

export const getWebAnalyticsContentAutopilotRunsRetrieveUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/web_analytics_content_autopilot_runs/${id}/`
}

export const webAnalyticsContentAutopilotRunsRetrieve = async (
    projectId: string,
    id: string,
    options?: RequestInit
): Promise<ContentAutopilotRunApi> => {
    return apiMutator<ContentAutopilotRunApi>(getWebAnalyticsContentAutopilotRunsRetrieveUrl(projectId, id), {
        ...options,
        method: 'GET',
    })
}

export const getWebAnalyticsContentAutopilotRunsCancelUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/web_analytics_content_autopilot_runs/${id}/cancel/`
}

/**
 * Stops a pending or generating run without creating content writes.
 * @summary Cancel a content autopilot run
 */
export const webAnalyticsContentAutopilotRunsCancel = async (
    projectId: string,
    id: string,
    options?: RequestInit
): Promise<ContentAutopilotRunApi> => {
    return apiMutator<ContentAutopilotRunApi>(getWebAnalyticsContentAutopilotRunsCancelUrl(projectId, id), {
        ...options,
        method: 'POST',
    })
}

export const getWebAnalyticsContentAutopilotRunsStartUrl = (projectId: string) => {
    return `/api/projects/${projectId}/web_analytics_content_autopilot_runs/start/`
}

/**
 * Captures the current profile and creates one pending on-demand content research run.
 * @summary Start a content autopilot run
 */
export const webAnalyticsContentAutopilotRunsStart = async (
    projectId: string,
    contentAutopilotRunStartRequestApi: ContentAutopilotRunStartRequestApi,
    options?: RequestInit
): Promise<ContentAutopilotRunApi> => {
    return apiMutator<ContentAutopilotRunApi>(getWebAnalyticsContentAutopilotRunsStartUrl(projectId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(contentAutopilotRunStartRequestApi),
    })
}

export const getWebAnalyticsFilterPresetsListUrl = (
    projectId: string,
    params?: WebAnalyticsFilterPresetsListParams
) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/web_analytics_filter_presets/?${stringifiedParams}`
        : `/api/projects/${projectId}/web_analytics_filter_presets/`
}

export const webAnalyticsFilterPresetsList = async (
    projectId: string,
    params?: WebAnalyticsFilterPresetsListParams,
    options?: RequestInit
): Promise<PaginatedWebAnalyticsFilterPresetListApi> => {
    return apiMutator<PaginatedWebAnalyticsFilterPresetListApi>(
        getWebAnalyticsFilterPresetsListUrl(projectId, params),
        {
            ...options,
            method: 'GET',
        }
    )
}

export const getWebAnalyticsFilterPresetsCreateUrl = (projectId: string) => {
    return `/api/projects/${projectId}/web_analytics_filter_presets/`
}

export const webAnalyticsFilterPresetsCreate = async (
    projectId: string,
    webAnalyticsFilterPresetApi: NonReadonly<WebAnalyticsFilterPresetApi>,
    options?: RequestInit
): Promise<WebAnalyticsFilterPresetApi> => {
    return apiMutator<WebAnalyticsFilterPresetApi>(getWebAnalyticsFilterPresetsCreateUrl(projectId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(webAnalyticsFilterPresetApi),
    })
}

export const getWebAnalyticsFilterPresetsRetrieveUrl = (projectId: string, shortId: string) => {
    return `/api/projects/${projectId}/web_analytics_filter_presets/${shortId}/`
}

export const webAnalyticsFilterPresetsRetrieve = async (
    projectId: string,
    shortId: string,
    options?: RequestInit
): Promise<WebAnalyticsFilterPresetApi> => {
    return apiMutator<WebAnalyticsFilterPresetApi>(getWebAnalyticsFilterPresetsRetrieveUrl(projectId, shortId), {
        ...options,
        method: 'GET',
    })
}

export const getWebAnalyticsFilterPresetsUpdateUrl = (projectId: string, shortId: string) => {
    return `/api/projects/${projectId}/web_analytics_filter_presets/${shortId}/`
}

export const webAnalyticsFilterPresetsUpdate = async (
    projectId: string,
    shortId: string,
    webAnalyticsFilterPresetApi: NonReadonly<WebAnalyticsFilterPresetApi>,
    options?: RequestInit
): Promise<WebAnalyticsFilterPresetApi> => {
    return apiMutator<WebAnalyticsFilterPresetApi>(getWebAnalyticsFilterPresetsUpdateUrl(projectId, shortId), {
        ...options,
        method: 'PUT',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(webAnalyticsFilterPresetApi),
    })
}

export const getWebAnalyticsFilterPresetsPartialUpdateUrl = (projectId: string, shortId: string) => {
    return `/api/projects/${projectId}/web_analytics_filter_presets/${shortId}/`
}

export const webAnalyticsFilterPresetsPartialUpdate = async (
    projectId: string,
    shortId: string,
    patchedWebAnalyticsFilterPresetApi?: NonReadonly<PatchedWebAnalyticsFilterPresetApi>,
    options?: RequestInit
): Promise<WebAnalyticsFilterPresetApi> => {
    return apiMutator<WebAnalyticsFilterPresetApi>(getWebAnalyticsFilterPresetsPartialUpdateUrl(projectId, shortId), {
        ...options,
        method: 'PATCH',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(patchedWebAnalyticsFilterPresetApi),
    })
}

export const getWebAnalyticsFilterPresetsDestroyUrl = (projectId: string, shortId: string) => {
    return `/api/projects/${projectId}/web_analytics_filter_presets/${shortId}/`
}

/**
 * Hard delete of this model is not allowed. Use a patch API call to set "deleted" to true
 */
export const webAnalyticsFilterPresetsDestroy = async (
    projectId: string,
    shortId: string,
    options?: RequestInit
): Promise<unknown> => {
    return apiMutator<unknown>(getWebAnalyticsFilterPresetsDestroyUrl(projectId, shortId), {
        ...options,
        method: 'DELETE',
    })
}

export const getWebAnalyticsPathCleaningSuggestionsApplyUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/web_analytics_path_cleaning_suggestions/${id}/apply/`
}

/**
 * Merges the suggestion's rules into the team's path_cleaning_filters (never overwrites existing rules) and resolves the underlying health issue. Requires project admin, matching the team API's gate on path_cleaning_filters.
 * @summary Apply a path-cleaning suggestion
 */
export const webAnalyticsPathCleaningSuggestionsApply = async (
    projectId: string,
    id: string,
    options?: RequestInit
): Promise<ApplyPathCleaningSuggestionResponseApi> => {
    return apiMutator<ApplyPathCleaningSuggestionResponseApi>(
        getWebAnalyticsPathCleaningSuggestionsApplyUrl(projectId, id),
        {
            ...options,
            method: 'POST',
        }
    )
}

export const getWebAnalyticsPathCleaningSuggestionsPreviewUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/web_analytics_path_cleaning_suggestions/${id}/preview/`
}

/**
 * Applies the suggestion's rules (in order) to a fresh sample of the team's top paths and returns before/after pairs for the paths that would change. Computed on demand; path samples are never stored. Nothing is modified.
 * @summary Preview a path-cleaning suggestion on real paths
 */
export const webAnalyticsPathCleaningSuggestionsPreview = async (
    projectId: string,
    id: string,
    options?: RequestInit
): Promise<PreviewPathCleaningSuggestionResponseApi> => {
    return apiMutator<PreviewPathCleaningSuggestionResponseApi>(
        getWebAnalyticsPathCleaningSuggestionsPreviewUrl(projectId, id),
        {
            ...options,
            method: 'GET',
        }
    )
}

export const getWebAnalyticsPathCleaningSuggestionsGenerateUrl = (projectId: string) => {
    return `/api/projects/${projectId}/web_analytics_path_cleaning_suggestions/generate/`
}

/**
 * Samples the team's recent paths, asks the LLM for cleaning rules, validates them against the real paths, and stores the result as a `path_cleaning_suggestions` health issue (replacing any previous active one). Runs even if the team already has rules. Returns the suggestion (or a skip status when there aren't enough paths to suggest from).
 * @summary Generate path-cleaning suggestions on demand
 */
export const webAnalyticsPathCleaningSuggestionsGenerate = async (
    projectId: string,
    options?: RequestInit
): Promise<GeneratePathCleaningSuggestionResponseApi> => {
    return apiMutator<GeneratePathCleaningSuggestionResponseApi>(
        getWebAnalyticsPathCleaningSuggestionsGenerateUrl(projectId),
        {
            ...options,
            method: 'POST',
        }
    )
}