// This file was auto-generated by Fern from our API Definition.

import * as Intercom from "../../../src/api/index";
import { IntercomClient } from "../../../src/Client";
import { mockServerPool } from "../../mock-server/MockServerPool";

describe("AiContentClient", () => {
    test("listContentImportSources (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });

        const rawResponseBody = {
            type: "list",
            pages: { type: "pages", page: 1, next: "next", per_page: 50, total_pages: 1 },
            total_count: 3,
            data: [
                {
                    type: "content_import_source",
                    id: 33,
                    last_synced_at: 1734537259,
                    sync_behavior: "automatic",
                    status: "active",
                    url: "https://support.example.com/us/1",
                    created_at: 1734537259,
                    updated_at: 1734537259,
                },
                {
                    type: "content_import_source",
                    id: 34,
                    last_synced_at: 1734537259,
                    sync_behavior: "automatic",
                    status: "active",
                    url: "https://support.example.com/us/2",
                    created_at: 1734537259,
                    updated_at: 1734537259,
                },
                {
                    type: "content_import_source",
                    id: 35,
                    last_synced_at: 1734537259,
                    sync_behavior: "automatic",
                    status: "active",
                    url: "https://support.example.com/us/3",
                    created_at: 1734537259,
                    updated_at: 1734537259,
                },
            ],
        };
        server
            .mockEndpoint()
            .get("/ai/content_import_sources")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.unstable.aiContent.listContentImportSources();
        expect(response).toEqual({
            type: "list",
            pages: {
                type: "pages",
                page: 1,
                next: "next",
                per_page: 50,
                total_pages: 1,
            },
            total_count: 3,
            data: [
                {
                    type: "content_import_source",
                    id: 33,
                    last_synced_at: 1734537259,
                    sync_behavior: "automatic",
                    status: "active",
                    url: "https://support.example.com/us/1",
                    created_at: 1734537259,
                    updated_at: 1734537259,
                },
                {
                    type: "content_import_source",
                    id: 34,
                    last_synced_at: 1734537259,
                    sync_behavior: "automatic",
                    status: "active",
                    url: "https://support.example.com/us/2",
                    created_at: 1734537259,
                    updated_at: 1734537259,
                },
                {
                    type: "content_import_source",
                    id: 35,
                    last_synced_at: 1734537259,
                    sync_behavior: "automatic",
                    status: "active",
                    url: "https://support.example.com/us/3",
                    created_at: 1734537259,
                    updated_at: 1734537259,
                },
            ],
        });
    });

    test("listContentImportSources (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });

        const rawResponseBody = { type: "type", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .get("/ai/content_import_sources")
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.unstable.aiContent.listContentImportSources();
        }).rejects.toThrow(Intercom.unstable.UnauthorizedError);
    });

    test("createContentImportSource (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { sync_behavior: "api", url: "https://www.example.com" };
        const rawResponseBody = {
            type: "content_import_source",
            id: 36,
            last_synced_at: 1734537261,
            sync_behavior: "api",
            status: "active",
            url: "https://www.example.com",
            created_at: 1734537261,
            updated_at: 1734537261,
        };
        server
            .mockEndpoint()
            .post("/ai/content_import_sources")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.unstable.aiContent.createContentImportSource({
            url: "https://www.example.com",
        });
        expect(response).toEqual({
            type: "content_import_source",
            id: 36,
            last_synced_at: 1734537261,
            sync_behavior: "api",
            status: "active",
            url: "https://www.example.com",
            created_at: 1734537261,
            updated_at: 1734537261,
        });
    });

    test("createContentImportSource (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { sync_behavior: "api", url: "url" };
        const rawResponseBody = { type: "type", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .post("/ai/content_import_sources")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.unstable.aiContent.createContentImportSource({
                url: "url",
            });
        }).rejects.toThrow(Intercom.unstable.UnauthorizedError);
    });

    test("getContentImportSource (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });

        const rawResponseBody = {
            type: "content_import_source",
            id: 38,
            last_synced_at: 1734537265,
            sync_behavior: "api",
            status: "active",
            url: "https://support.example.com/us/5",
            created_at: 1734537265,
            updated_at: 1734537265,
        };
        server
            .mockEndpoint()
            .get("/ai/content_import_sources/id")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.unstable.aiContent.getContentImportSource({
            id: "id",
        });
        expect(response).toEqual({
            type: "content_import_source",
            id: 38,
            last_synced_at: 1734537265,
            sync_behavior: "api",
            status: "active",
            url: "https://support.example.com/us/5",
            created_at: 1734537265,
            updated_at: 1734537265,
        });
    });

    test("getContentImportSource (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });

        const rawResponseBody = { type: "type", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .get("/ai/content_import_sources/id")
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.unstable.aiContent.getContentImportSource({
                id: "id",
            });
        }).rejects.toThrow(Intercom.unstable.UnauthorizedError);
    });

    test("updateContentImportSource (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { sync_behavior: "api", url: "https://www.example.com" };
        const rawResponseBody = {
            type: "content_import_source",
            id: 39,
            last_synced_at: 1734537267,
            sync_behavior: "api",
            status: "active",
            url: "https://www.example.com",
            created_at: 1734537267,
            updated_at: 1734537267,
        };
        server
            .mockEndpoint()
            .put("/ai/content_import_sources/id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.unstable.aiContent.updateContentImportSource({
            id: "id",
            sync_behavior: "api",
            url: "https://www.example.com",
        });
        expect(response).toEqual({
            type: "content_import_source",
            id: 39,
            last_synced_at: 1734537267,
            sync_behavior: "api",
            status: "active",
            url: "https://www.example.com",
            created_at: 1734537267,
            updated_at: 1734537267,
        });
    });

    test("updateContentImportSource (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { sync_behavior: "api", url: "url" };
        const rawResponseBody = { type: "type", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .put("/ai/content_import_sources/id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.unstable.aiContent.updateContentImportSource({
                id: "id",
                sync_behavior: "api",
                url: "url",
            });
        }).rejects.toThrow(Intercom.unstable.UnauthorizedError);
    });

    test("deleteContentImportSource (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });

        server.mockEndpoint().delete("/ai/content_import_sources/id").respondWith().statusCode(200).build();

        const response = await client.unstable.aiContent.deleteContentImportSource({
            id: "id",
        });
        expect(response).toEqual(undefined);
    });

    test("deleteContentImportSource (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });

        const rawResponseBody = { type: "type", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .delete("/ai/content_import_sources/id")
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.unstable.aiContent.deleteContentImportSource({
                id: "id",
            });
        }).rejects.toThrow(Intercom.unstable.UnauthorizedError);
    });

    test("listExternalPages (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });

        const rawResponseBody = {
            type: "list",
            pages: { type: "pages", page: 1, next: "next", per_page: 50, total_pages: 1 },
            total_count: 3,
            data: [
                {
                    type: "external_page",
                    id: "19",
                    title: "My External Content",
                    html: "<h1>Hello world</h1><p>This is external content</p>",
                    url: "https://support.example.com/us/3",
                    ai_agent_availability: true,
                    ai_copilot_availability: true,
                    fin_availability: true,
                    locale: "en",
                    source_id: 42,
                    external_id: "3",
                    created_at: 1734537269,
                    updated_at: 1734537269,
                    last_ingested_at: 1734537269,
                },
                {
                    type: "external_page",
                    id: "18",
                    title: "My External Content",
                    html: "<h1>Hello world</h1><p>This is external content</p>",
                    url: "https://support.example.com/us/2",
                    ai_agent_availability: true,
                    ai_copilot_availability: true,
                    fin_availability: true,
                    locale: "en",
                    source_id: 41,
                    external_id: "2",
                    created_at: 1734537269,
                    updated_at: 1734537269,
                    last_ingested_at: 1734537269,
                },
                {
                    type: "external_page",
                    id: "17",
                    title: "My External Content",
                    html: "<h1>Hello world</h1><p>This is external content</p>",
                    url: "https://support.example.com/us/1",
                    ai_agent_availability: true,
                    ai_copilot_availability: true,
                    fin_availability: true,
                    locale: "en",
                    source_id: 40,
                    external_id: "1",
                    created_at: 1734537269,
                    updated_at: 1734537269,
                    last_ingested_at: 1734537269,
                },
            ],
        };
        server.mockEndpoint().get("/ai/external_pages").respondWith().statusCode(200).jsonBody(rawResponseBody).build();

        const response = await client.unstable.aiContent.listExternalPages();
        expect(response).toEqual({
            type: "list",
            pages: {
                type: "pages",
                page: 1,
                next: "next",
                per_page: 50,
                total_pages: 1,
            },
            total_count: 3,
            data: [
                {
                    type: "external_page",
                    id: "19",
                    title: "My External Content",
                    html: "<h1>Hello world</h1><p>This is external content</p>",
                    url: "https://support.example.com/us/3",
                    ai_agent_availability: true,
                    ai_copilot_availability: true,
                    fin_availability: true,
                    locale: "en",
                    source_id: 42,
                    external_id: "3",
                    created_at: 1734537269,
                    updated_at: 1734537269,
                    last_ingested_at: 1734537269,
                },
                {
                    type: "external_page",
                    id: "18",
                    title: "My External Content",
                    html: "<h1>Hello world</h1><p>This is external content</p>",
                    url: "https://support.example.com/us/2",
                    ai_agent_availability: true,
                    ai_copilot_availability: true,
                    fin_availability: true,
                    locale: "en",
                    source_id: 41,
                    external_id: "2",
                    created_at: 1734537269,
                    updated_at: 1734537269,
                    last_ingested_at: 1734537269,
                },
                {
                    type: "external_page",
                    id: "17",
                    title: "My External Content",
                    html: "<h1>Hello world</h1><p>This is external content</p>",
                    url: "https://support.example.com/us/1",
                    ai_agent_availability: true,
                    ai_copilot_availability: true,
                    fin_availability: true,
                    locale: "en",
                    source_id: 40,
                    external_id: "1",
                    created_at: 1734537269,
                    updated_at: 1734537269,
                    last_ingested_at: 1734537269,
                },
            ],
        });
    });

    test("listExternalPages (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });

        const rawResponseBody = { type: "type", errors: [{ code: "code" }, { code: "code" }] };
        server.mockEndpoint().get("/ai/external_pages").respondWith().statusCode(401).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.unstable.aiContent.listExternalPages();
        }).rejects.toThrow(Intercom.unstable.UnauthorizedError);
    });

    test("createExternalPage (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            title: "Test",
            html: "<html><body><h1>Test</h1></body></html>",
            url: "https://www.example.com",
            locale: "en",
            source_id: 44,
            external_id: "abc1234",
        };
        const rawResponseBody = {
            type: "external_page",
            id: "21",
            title: "Test",
            html: "<html><body><h1>Test</h1></body></html>",
            url: "https://www.example.com",
            ai_agent_availability: true,
            ai_copilot_availability: true,
            fin_availability: true,
            locale: "en",
            source_id: 44,
            external_id: "abc1234",
            created_at: 1734537273,
            updated_at: 1734537274,
            last_ingested_at: 1734537274,
        };
        server
            .mockEndpoint()
            .post("/ai/external_pages")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.unstable.aiContent.createExternalPage({
            title: "Test",
            html: "<html><body><h1>Test</h1></body></html>",
            url: "https://www.example.com",
            source_id: 44,
            external_id: "abc1234",
        });
        expect(response).toEqual({
            type: "external_page",
            id: "21",
            title: "Test",
            html: "<html><body><h1>Test</h1></body></html>",
            url: "https://www.example.com",
            ai_agent_availability: true,
            ai_copilot_availability: true,
            fin_availability: true,
            locale: "en",
            source_id: 44,
            external_id: "abc1234",
            created_at: 1734537273,
            updated_at: 1734537274,
            last_ingested_at: 1734537274,
        });
    });

    test("createExternalPage (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { title: "title", html: "html", locale: "en", source_id: 1, external_id: "external_id" };
        const rawResponseBody = { type: "type", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .post("/ai/external_pages")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.unstable.aiContent.createExternalPage({
                title: "title",
                html: "html",
                source_id: 1,
                external_id: "external_id",
            });
        }).rejects.toThrow(Intercom.unstable.UnauthorizedError);
    });

    test("getExternalPage (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });

        const rawResponseBody = {
            type: "external_page",
            id: "23",
            title: "My External Content",
            html: "<h1>Hello world</h1><p>This is external content</p>",
            url: "https://support.example.com/us/6",
            ai_agent_availability: true,
            ai_copilot_availability: true,
            fin_availability: true,
            locale: "en",
            source_id: 46,
            external_id: "5",
            created_at: 1734537278,
            updated_at: 1734537278,
            last_ingested_at: 1734537278,
        };
        server
            .mockEndpoint()
            .get("/ai/external_pages/id")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.unstable.aiContent.getExternalPage({
            id: "id",
        });
        expect(response).toEqual({
            type: "external_page",
            id: "23",
            title: "My External Content",
            html: "<h1>Hello world</h1><p>This is external content</p>",
            url: "https://support.example.com/us/6",
            ai_agent_availability: true,
            ai_copilot_availability: true,
            fin_availability: true,
            locale: "en",
            source_id: 46,
            external_id: "5",
            created_at: 1734537278,
            updated_at: 1734537278,
            last_ingested_at: 1734537278,
        });
    });

    test("getExternalPage (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });

        const rawResponseBody = { type: "type", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .get("/ai/external_pages/id")
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.unstable.aiContent.getExternalPage({
                id: "id",
            });
        }).rejects.toThrow(Intercom.unstable.UnauthorizedError);
    });

    test("updateExternalPage (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            title: "Test",
            html: "<html><body><h1>Test</h1></body></html>",
            url: "https://www.example.com",
            locale: "en",
            source_id: 47,
            external_id: "5678",
        };
        const rawResponseBody = {
            type: "external_page",
            id: "24",
            title: "Test",
            html: "<html><body><h1>Test</h1></body></html>",
            url: "https://www.example.com",
            ai_agent_availability: true,
            ai_copilot_availability: true,
            fin_availability: true,
            locale: "en",
            source_id: 47,
            external_id: "5678",
            created_at: 1734537280,
            updated_at: 1734537281,
            last_ingested_at: 1734537281,
        };
        server
            .mockEndpoint()
            .put("/ai/external_pages/id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.unstable.aiContent.updateExternalPage({
            id: "id",
            title: "Test",
            html: "<html><body><h1>Test</h1></body></html>",
            url: "https://www.example.com",
            source_id: 47,
            external_id: "5678",
        });
        expect(response).toEqual({
            type: "external_page",
            id: "24",
            title: "Test",
            html: "<html><body><h1>Test</h1></body></html>",
            url: "https://www.example.com",
            ai_agent_availability: true,
            ai_copilot_availability: true,
            fin_availability: true,
            locale: "en",
            source_id: 47,
            external_id: "5678",
            created_at: 1734537280,
            updated_at: 1734537281,
            last_ingested_at: 1734537281,
        });
    });

    test("updateExternalPage (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { title: "title", html: "html", url: "url", locale: "en", source_id: 1 };
        const rawResponseBody = { type: "type", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .put("/ai/external_pages/id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.unstable.aiContent.updateExternalPage({
                id: "id",
                title: "title",
                html: "html",
                url: "url",
                source_id: 1,
            });
        }).rejects.toThrow(Intercom.unstable.UnauthorizedError);
    });

    test("deleteExternalPage (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });

        const rawResponseBody = {
            type: "external_page",
            id: "22",
            title: "My External Content",
            html: "",
            url: "https://support.example.com/us/5",
            ai_agent_availability: true,
            ai_copilot_availability: true,
            fin_availability: true,
            locale: "en",
            source_id: 45,
            external_id: "4",
            created_at: 1734537276,
            updated_at: 1734537276,
            last_ingested_at: 1734537276,
        };
        server
            .mockEndpoint()
            .delete("/ai/external_pages/id")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.unstable.aiContent.deleteExternalPage({
            id: "id",
        });
        expect(response).toEqual({
            type: "external_page",
            id: "22",
            title: "My External Content",
            html: "",
            url: "https://support.example.com/us/5",
            ai_agent_availability: true,
            ai_copilot_availability: true,
            fin_availability: true,
            locale: "en",
            source_id: 45,
            external_id: "4",
            created_at: 1734537276,
            updated_at: 1734537276,
            last_ingested_at: 1734537276,
        });
    });

    test("deleteExternalPage (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });

        const rawResponseBody = { type: "type", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .delete("/ai/external_pages/id")
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.unstable.aiContent.deleteExternalPage({
                id: "id",
            });
        }).rejects.toThrow(Intercom.unstable.UnauthorizedError);
    });
});
