// 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("NotesClient", () => {
    test("listCompanyNotes (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });

        const rawResponseBody = {
            type: "list",
            data: [
                {
                    type: "note",
                    id: "26",
                    created_at: 1733932587,
                    contact: { id: "214656d0c743eafcfde7f248" },
                    author: {
                        type: "admin",
                        id: "991267581",
                        name: "Ciaran122 Lee",
                        email: "admin122@email.com",
                        job_title: "Associate",
                        away_mode_enabled: false,
                        away_mode_reassign: false,
                        away_status_reason_id: 12345,
                        has_inbox_seat: true,
                        team_ids: [814865],
                        avatar: "https://picsum.photos/200/300",
                        team_priority_level: { primary_team_ids: [814865], secondary_team_ids: [493881] },
                    },
                    body: "<p>This is a note.</p>",
                },
                {
                    type: "note",
                    id: "25",
                    created_at: 1733846187,
                    contact: { id: "214656d0c743eafcfde7f248" },
                    author: {
                        type: "admin",
                        id: "991267581",
                        name: "Ciaran122 Lee",
                        email: "admin122@email.com",
                        job_title: "Associate",
                        away_mode_enabled: false,
                        away_mode_reassign: false,
                        away_status_reason_id: 12345,
                        has_inbox_seat: true,
                        team_ids: [814865],
                        avatar: "https://picsum.photos/200/300",
                    },
                    body: "<p>This is a note.</p>",
                },
                {
                    type: "note",
                    id: "24",
                    created_at: 1733846187,
                    contact: { id: "214656d0c743eafcfde7f248" },
                    author: {
                        type: "admin",
                        id: "991267581",
                        name: "Ciaran122 Lee",
                        email: "admin122@email.com",
                        job_title: "Associate",
                        away_mode_enabled: false,
                        away_mode_reassign: false,
                        away_status_reason_id: 12345,
                        has_inbox_seat: true,
                        team_ids: [814865],
                        avatar: "https://picsum.photos/200/300",
                        team_priority_level: { primary_team_ids: [814865], secondary_team_ids: [493881] },
                    },
                    body: "<p>This is a note.</p>",
                },
            ],
            total_count: 3,
            pages: {
                type: "pages",
                page: 1,
                next: { per_page: 2, starting_after: "your-cursor-from-response" },
                per_page: 50,
                total_pages: 1,
            },
        };
        server
            .mockEndpoint()
            .get("/companies/5f4d3c1c-7b1b-4d7d-a97e-6095715c6632/notes")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.unstable.notes.listCompanyNotes({
            id: "5f4d3c1c-7b1b-4d7d-a97e-6095715c6632",
        });
        expect(response).toEqual({
            type: "list",
            data: [
                {
                    type: "note",
                    id: "26",
                    created_at: 1733932587,
                    contact: {
                        id: "214656d0c743eafcfde7f248",
                    },
                    author: {
                        type: "admin",
                        id: "991267581",
                        name: "Ciaran122 Lee",
                        email: "admin122@email.com",
                        job_title: "Associate",
                        away_mode_enabled: false,
                        away_mode_reassign: false,
                        away_status_reason_id: 12345,
                        has_inbox_seat: true,
                        team_ids: [814865],
                        avatar: "https://picsum.photos/200/300",
                        team_priority_level: {
                            primary_team_ids: [814865],
                            secondary_team_ids: [493881],
                        },
                    },
                    body: "<p>This is a note.</p>",
                },
                {
                    type: "note",
                    id: "25",
                    created_at: 1733846187,
                    contact: {
                        id: "214656d0c743eafcfde7f248",
                    },
                    author: {
                        type: "admin",
                        id: "991267581",
                        name: "Ciaran122 Lee",
                        email: "admin122@email.com",
                        job_title: "Associate",
                        away_mode_enabled: false,
                        away_mode_reassign: false,
                        away_status_reason_id: 12345,
                        has_inbox_seat: true,
                        team_ids: [814865],
                        avatar: "https://picsum.photos/200/300",
                    },
                    body: "<p>This is a note.</p>",
                },
                {
                    type: "note",
                    id: "24",
                    created_at: 1733846187,
                    contact: {
                        id: "214656d0c743eafcfde7f248",
                    },
                    author: {
                        type: "admin",
                        id: "991267581",
                        name: "Ciaran122 Lee",
                        email: "admin122@email.com",
                        job_title: "Associate",
                        away_mode_enabled: false,
                        away_mode_reassign: false,
                        away_status_reason_id: 12345,
                        has_inbox_seat: true,
                        team_ids: [814865],
                        avatar: "https://picsum.photos/200/300",
                        team_priority_level: {
                            primary_team_ids: [814865],
                            secondary_team_ids: [493881],
                        },
                    },
                    body: "<p>This is a note.</p>",
                },
            ],
            total_count: 3,
            pages: {
                type: "pages",
                page: 1,
                next: {
                    per_page: 2,
                    starting_after: "your-cursor-from-response",
                },
                per_page: 50,
                total_pages: 1,
            },
        });
    });

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

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .get("/companies/id/notes")
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.unstable.notes.listCompanyNotes({
                id: "id",
            });
        }).rejects.toThrow(Intercom.unstable.NotFoundError);
    });

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

        const rawResponseBody = {
            type: "list",
            data: [
                {
                    type: "note",
                    id: "26",
                    created_at: 1733932587,
                    contact: { type: "contact", id: "6762f0ab1bb69f9f2193bb60" },
                    author: {
                        type: "admin",
                        id: "991267581",
                        name: "Ciaran122 Lee",
                        email: "admin122@email.com",
                        job_title: "Associate",
                        away_mode_enabled: false,
                        away_mode_reassign: false,
                        away_status_reason_id: 12345,
                        has_inbox_seat: true,
                        team_ids: [814865],
                        avatar: "https://picsum.photos/200/300",
                    },
                    body: "<p>This is a note.</p>",
                },
                {
                    type: "note",
                    id: "25",
                    created_at: 1733846187,
                    contact: { type: "contact", id: "6762f0ab1bb69f9f2193bb60" },
                    author: {
                        type: "admin",
                        id: "991267581",
                        name: "Ciaran122 Lee",
                        email: "admin122@email.com",
                        job_title: "Associate",
                        away_mode_enabled: false,
                        away_mode_reassign: false,
                        away_status_reason_id: 12345,
                        has_inbox_seat: true,
                        team_ids: [814865],
                        avatar: "https://picsum.photos/200/300",
                    },
                    body: "<p>This is a note.</p>",
                },
                {
                    type: "note",
                    id: "24",
                    created_at: 1733846187,
                    contact: { type: "contact", id: "6762f0ab1bb69f9f2193bb60" },
                    author: {
                        type: "admin",
                        id: "991267581",
                        name: "Ciaran122 Lee",
                        email: "admin122@email.com",
                        job_title: "Associate",
                        away_mode_enabled: false,
                        away_mode_reassign: false,
                        away_status_reason_id: 12345,
                        has_inbox_seat: true,
                        team_ids: [814865],
                        avatar: "https://picsum.photos/200/300",
                    },
                    body: "<p>This is a note.</p>",
                },
            ],
            total_count: 3,
            pages: {
                type: "pages",
                page: 1,
                next: { per_page: 2, starting_after: "your-cursor-from-response" },
                per_page: 50,
                total_pages: 1,
            },
        };
        server.mockEndpoint().get("/contacts/1/notes").respondWith().statusCode(200).jsonBody(rawResponseBody).build();

        const response = await client.unstable.notes.listNotes({
            id: 1,
        });
        expect(response).toEqual({
            type: "list",
            data: [
                {
                    type: "note",
                    id: "26",
                    created_at: 1733932587,
                    contact: {
                        type: "contact",
                        id: "6762f0ab1bb69f9f2193bb60",
                    },
                    author: {
                        type: "admin",
                        id: "991267581",
                        name: "Ciaran122 Lee",
                        email: "admin122@email.com",
                        job_title: "Associate",
                        away_mode_enabled: false,
                        away_mode_reassign: false,
                        away_status_reason_id: 12345,
                        has_inbox_seat: true,
                        team_ids: [814865],
                        avatar: "https://picsum.photos/200/300",
                    },
                    body: "<p>This is a note.</p>",
                },
                {
                    type: "note",
                    id: "25",
                    created_at: 1733846187,
                    contact: {
                        type: "contact",
                        id: "6762f0ab1bb69f9f2193bb60",
                    },
                    author: {
                        type: "admin",
                        id: "991267581",
                        name: "Ciaran122 Lee",
                        email: "admin122@email.com",
                        job_title: "Associate",
                        away_mode_enabled: false,
                        away_mode_reassign: false,
                        away_status_reason_id: 12345,
                        has_inbox_seat: true,
                        team_ids: [814865],
                        avatar: "https://picsum.photos/200/300",
                    },
                    body: "<p>This is a note.</p>",
                },
                {
                    type: "note",
                    id: "24",
                    created_at: 1733846187,
                    contact: {
                        type: "contact",
                        id: "6762f0ab1bb69f9f2193bb60",
                    },
                    author: {
                        type: "admin",
                        id: "991267581",
                        name: "Ciaran122 Lee",
                        email: "admin122@email.com",
                        job_title: "Associate",
                        away_mode_enabled: false,
                        away_mode_reassign: false,
                        away_status_reason_id: 12345,
                        has_inbox_seat: true,
                        team_ids: [814865],
                        avatar: "https://picsum.photos/200/300",
                    },
                    body: "<p>This is a note.</p>",
                },
            ],
            total_count: 3,
            pages: {
                type: "pages",
                page: 1,
                next: {
                    per_page: 2,
                    starting_after: "your-cursor-from-response",
                },
                per_page: 50,
                total_pages: 1,
            },
        });
    });

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

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/contacts/1/notes").respondWith().statusCode(404).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.unstable.notes.listNotes({
                id: 1,
            });
        }).rejects.toThrow(Intercom.unstable.NotFoundError);
    });

    test("createNote (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { body: "Hello", contact_id: "6762f0ad1bb69f9f2193bb62", admin_id: "123" };
        const rawResponseBody = {
            type: "note",
            id: "31",
            created_at: 1734537390,
            contact: { type: "contact", id: "6762f0ad1bb69f9f2193bb62" },
            author: {
                type: "admin",
                id: "991267583",
                name: "Ciaran124 Lee",
                email: "admin124@email.com",
                job_title: "Associate",
                away_mode_enabled: false,
                away_mode_reassign: false,
                away_status_reason_id: 12345,
                has_inbox_seat: true,
                team_ids: [814865],
                avatar: "https://picsum.photos/200/300",
                team_priority_level: { primary_team_ids: [814865], secondary_team_ids: [493881] },
            },
            body: "<p>Hello</p>",
        };
        server
            .mockEndpoint()
            .post("/contacts/1/notes")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.unstable.notes.createNote({
            id: 1,
            body: "Hello",
            contact_id: "6762f0ad1bb69f9f2193bb62",
            admin_id: "123",
        });
        expect(response).toEqual({
            type: "note",
            id: "31",
            created_at: 1734537390,
            contact: {
                type: "contact",
                id: "6762f0ad1bb69f9f2193bb62",
            },
            author: {
                type: "admin",
                id: "991267583",
                name: "Ciaran124 Lee",
                email: "admin124@email.com",
                job_title: "Associate",
                away_mode_enabled: false,
                away_mode_reassign: false,
                away_status_reason_id: 12345,
                has_inbox_seat: true,
                team_ids: [814865],
                avatar: "https://picsum.photos/200/300",
                team_priority_level: {
                    primary_team_ids: [814865],
                    secondary_team_ids: [493881],
                },
            },
            body: "<p>Hello</p>",
        });
    });

    test("createNote (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { body: "Hello", contact_id: "6762f0af1bb69f9f2193bb63", admin_id: "123" };
        const rawResponseBody = {
            type: "note",
            id: "31",
            created_at: 1734537390,
            contact: { type: "contact", id: "6762f0ad1bb69f9f2193bb62" },
            author: {
                type: "admin",
                id: "991267583",
                name: "Ciaran124 Lee",
                email: "admin124@email.com",
                job_title: "Associate",
                away_mode_enabled: false,
                away_mode_reassign: false,
                away_status_reason_id: 12345,
                has_inbox_seat: true,
                team_ids: [814865],
                avatar: "https://picsum.photos/200/300",
                team_priority_level: { primary_team_ids: [814865], secondary_team_ids: [493881] },
            },
            body: "<p>Hello</p>",
        };
        server
            .mockEndpoint()
            .post("/contacts/1/notes")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.unstable.notes.createNote({
            id: 1,
            body: "Hello",
            contact_id: "6762f0af1bb69f9f2193bb63",
            admin_id: "123",
        });
        expect(response).toEqual({
            type: "note",
            id: "31",
            created_at: 1734537390,
            contact: {
                type: "contact",
                id: "6762f0ad1bb69f9f2193bb62",
            },
            author: {
                type: "admin",
                id: "991267583",
                name: "Ciaran124 Lee",
                email: "admin124@email.com",
                job_title: "Associate",
                away_mode_enabled: false,
                away_mode_reassign: false,
                away_status_reason_id: 12345,
                has_inbox_seat: true,
                team_ids: [814865],
                avatar: "https://picsum.photos/200/300",
                team_priority_level: {
                    primary_team_ids: [814865],
                    secondary_team_ids: [493881],
                },
            },
            body: "<p>Hello</p>",
        });
    });

    test("createNote (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { body: "Hello", contact_id: "123", admin_id: "123" };
        const rawResponseBody = {
            type: "note",
            id: "31",
            created_at: 1734537390,
            contact: { type: "contact", id: "6762f0ad1bb69f9f2193bb62" },
            author: {
                type: "admin",
                id: "991267583",
                name: "Ciaran124 Lee",
                email: "admin124@email.com",
                job_title: "Associate",
                away_mode_enabled: false,
                away_mode_reassign: false,
                away_status_reason_id: 12345,
                has_inbox_seat: true,
                team_ids: [814865],
                avatar: "https://picsum.photos/200/300",
                team_priority_level: { primary_team_ids: [814865], secondary_team_ids: [493881] },
            },
            body: "<p>Hello</p>",
        };
        server
            .mockEndpoint()
            .post("/contacts/1/notes")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.unstable.notes.createNote({
            id: 1,
            body: "Hello",
            contact_id: "123",
            admin_id: "123",
        });
        expect(response).toEqual({
            type: "note",
            id: "31",
            created_at: 1734537390,
            contact: {
                type: "contact",
                id: "6762f0ad1bb69f9f2193bb62",
            },
            author: {
                type: "admin",
                id: "991267583",
                name: "Ciaran124 Lee",
                email: "admin124@email.com",
                job_title: "Associate",
                away_mode_enabled: false,
                away_mode_reassign: false,
                away_status_reason_id: 12345,
                has_inbox_seat: true,
                team_ids: [814865],
                avatar: "https://picsum.photos/200/300",
                team_priority_level: {
                    primary_team_ids: [814865],
                    secondary_team_ids: [493881],
                },
            },
            body: "<p>Hello</p>",
        });
    });

    test("createNote (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { body: "body" };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/contacts/1/notes")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.unstable.notes.createNote({
                id: 1,
                body: "body",
            });
        }).rejects.toThrow(Intercom.unstable.NotFoundError);
    });

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

        const rawResponseBody = {
            type: "note",
            id: "34",
            created_at: 1733846617,
            contact: { type: "contact", id: "6762f2591bb69f9f2193bc1f" },
            author: {
                type: "admin",
                id: "991267864",
                name: "Ciaran346 Lee",
                email: "admin346@email.com",
                job_title: "Associate",
                away_mode_enabled: false,
                away_mode_reassign: false,
                away_status_reason_id: 12345,
                has_inbox_seat: true,
                team_ids: [814865],
                avatar: "https://picsum.photos/200/300",
                team_priority_level: { primary_team_ids: [814865], secondary_team_ids: [493881] },
            },
            body: "<p>This is a note.</p>",
        };
        server.mockEndpoint().get("/notes/1").respondWith().statusCode(200).jsonBody(rawResponseBody).build();

        const response = await client.unstable.notes.retrieveNote({
            id: 1,
        });
        expect(response).toEqual({
            type: "note",
            id: "34",
            created_at: 1733846617,
            contact: {
                type: "contact",
                id: "6762f2591bb69f9f2193bc1f",
            },
            author: {
                type: "admin",
                id: "991267864",
                name: "Ciaran346 Lee",
                email: "admin346@email.com",
                job_title: "Associate",
                away_mode_enabled: false,
                away_mode_reassign: false,
                away_status_reason_id: 12345,
                has_inbox_seat: true,
                team_ids: [814865],
                avatar: "https://picsum.photos/200/300",
                team_priority_level: {
                    primary_team_ids: [814865],
                    secondary_team_ids: [493881],
                },
            },
            body: "<p>This is a note.</p>",
        });
    });

    test("retrieveNote (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("/notes/1").respondWith().statusCode(401).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.unstable.notes.retrieveNote({
                id: 1,
            });
        }).rejects.toThrow(Intercom.unstable.UnauthorizedError);
    });

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

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/notes/1").respondWith().statusCode(404).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.unstable.notes.retrieveNote({
                id: 1,
            });
        }).rejects.toThrow(Intercom.unstable.NotFoundError);
    });
});
