// 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("TicketTypesClient", () => {
    test("listTicketTypes (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: "ticket_type",
                    id: "67",
                    category: "Customer",
                    name: "Bug Report",
                    description: "Bug Report Template",
                    icon: "🎟️",
                    workspace_id: "this_is_an_id648_that_should_be_at_least_",
                    ticket_type_attributes: { type: "list" },
                    ticket_states: {
                        type: "list",
                        data: [
                            {
                                type: "ticket_state",
                                id: "8321",
                                category: "submitted",
                                internal_label: "Submitted",
                                external_label: "Submitted",
                            },
                            {
                                type: "ticket_state",
                                id: "8322",
                                category: "in_progress",
                                internal_label: "In progress",
                                external_label: "In progress",
                            },
                            {
                                type: "ticket_state",
                                id: "8323",
                                category: "waiting_on_customer",
                                internal_label: "Waiting on customer",
                                external_label: "Waiting on you",
                            },
                            {
                                type: "ticket_state",
                                id: "8324",
                                category: "resolved",
                                internal_label: "Resolved",
                                external_label: "Resolved",
                            },
                        ],
                    },
                    archived: false,
                    created_at: 1734537866,
                    updated_at: 1734537866,
                },
            ],
        };
        server.mockEndpoint().get("/ticket_types").respondWith().statusCode(200).jsonBody(rawResponseBody).build();

        const response = await client.unstable.ticketTypes.listTicketTypes();
        expect(response).toEqual({
            type: "list",
            data: [
                {
                    type: "ticket_type",
                    id: "67",
                    category: "Customer",
                    name: "Bug Report",
                    description: "Bug Report Template",
                    icon: "\uD83C\uDF9F\uFE0F",
                    workspace_id: "this_is_an_id648_that_should_be_at_least_",
                    ticket_type_attributes: {
                        type: "list",
                    },
                    ticket_states: {
                        type: "list",
                        data: [
                            {
                                type: "ticket_state",
                                id: "8321",
                                category: "submitted",
                                internal_label: "Submitted",
                                external_label: "Submitted",
                            },
                            {
                                type: "ticket_state",
                                id: "8322",
                                category: "in_progress",
                                internal_label: "In progress",
                                external_label: "In progress",
                            },
                            {
                                type: "ticket_state",
                                id: "8323",
                                category: "waiting_on_customer",
                                internal_label: "Waiting on customer",
                                external_label: "Waiting on you",
                            },
                            {
                                type: "ticket_state",
                                id: "8324",
                                category: "resolved",
                                internal_label: "Resolved",
                                external_label: "Resolved",
                            },
                        ],
                    },
                    archived: false,
                    created_at: 1734537866,
                    updated_at: 1734537866,
                },
            ],
        });
    });

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

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

    test("createTicketType (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = { key: "value" };
        const rawResponseBody = {
            type: "type",
            id: "id",
            category: "Customer",
            name: "name",
            description: "description",
            icon: "icon",
            workspace_id: "workspace_id",
            ticket_type_attributes: {
                type: "type",
                ticket_type_attributes: [
                    {
                        type: "type",
                        id: "id",
                        workspace_id: "workspace_id",
                        name: "name",
                        description: "description",
                        data_type: "data_type",
                        input_options: { input_options: { key: "value" } },
                        order: 1,
                        required_to_create: true,
                        required_to_create_for_contacts: true,
                        visible_on_create: true,
                        visible_to_contacts: true,
                        default: true,
                        ticket_type_id: 1,
                        archived: true,
                        created_at: 1,
                        updated_at: 1,
                    },
                    {
                        type: "type",
                        id: "id",
                        workspace_id: "workspace_id",
                        name: "name",
                        description: "description",
                        data_type: "data_type",
                        input_options: { input_options: { key: "value" } },
                        order: 1,
                        required_to_create: true,
                        required_to_create_for_contacts: true,
                        visible_on_create: true,
                        visible_to_contacts: true,
                        default: true,
                        ticket_type_id: 1,
                        archived: true,
                        created_at: 1,
                        updated_at: 1,
                    },
                ],
            },
            ticket_states: {
                type: "type",
                data: [
                    {
                        type: "type",
                        id: "id",
                        category: "submitted",
                        internal_label: "internal_label",
                        external_label: "external_label",
                    },
                    {
                        type: "type",
                        id: "id",
                        category: "submitted",
                        internal_label: "internal_label",
                        external_label: "external_label",
                    },
                ],
            },
            archived: true,
            created_at: 1,
            updated_at: 1,
        };
        server
            .mockEndpoint()
            .post("/ticket_types")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.unstable.ticketTypes.createTicketType({
            key: "value",
        });
        expect(response).toEqual({
            type: "type",
            id: "id",
            category: "Customer",
            name: "name",
            description: "description",
            icon: "icon",
            workspace_id: "workspace_id",
            ticket_type_attributes: {
                type: "type",
                ticket_type_attributes: [
                    {
                        type: "type",
                        id: "id",
                        workspace_id: "workspace_id",
                        name: "name",
                        description: "description",
                        data_type: "data_type",
                        input_options: {
                            input_options: {
                                key: "value",
                            },
                        },
                        order: 1,
                        required_to_create: true,
                        required_to_create_for_contacts: true,
                        visible_on_create: true,
                        visible_to_contacts: true,
                        default: true,
                        ticket_type_id: 1,
                        archived: true,
                        created_at: 1,
                        updated_at: 1,
                    },
                    {
                        type: "type",
                        id: "id",
                        workspace_id: "workspace_id",
                        name: "name",
                        description: "description",
                        data_type: "data_type",
                        input_options: {
                            input_options: {
                                key: "value",
                            },
                        },
                        order: 1,
                        required_to_create: true,
                        required_to_create_for_contacts: true,
                        visible_on_create: true,
                        visible_to_contacts: true,
                        default: true,
                        ticket_type_id: 1,
                        archived: true,
                        created_at: 1,
                        updated_at: 1,
                    },
                ],
            },
            ticket_states: {
                type: "type",
                data: [
                    {
                        type: "type",
                        id: "id",
                        category: "submitted",
                        internal_label: "internal_label",
                        external_label: "external_label",
                    },
                    {
                        type: "type",
                        id: "id",
                        category: "submitted",
                        internal_label: "internal_label",
                        external_label: "external_label",
                    },
                ],
            },
            archived: true,
            created_at: 1,
            updated_at: 1,
        });
    });

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

        await expect(async () => {
            return await client.unstable.ticketTypes.createTicketType({
                key: "value",
            });
        }).rejects.toThrow(Intercom.unstable.UnauthorizedError);
    });

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

        const rawResponseBody = {
            type: "ticket_type",
            id: "72",
            category: "Customer",
            name: "Bug Report",
            description: "Bug Report Template",
            icon: "🎟️",
            workspace_id: "this_is_an_id656_that_should_be_at_least_",
            ticket_type_attributes: {
                type: "list",
                ticket_type_attributes: [
                    {
                        type: "ticket_type_attribute",
                        id: "1",
                        workspace_id: "ecahpwf5",
                        name: "Title",
                        description: "Bug title.",
                        data_type: "string",
                        input_options: { key: "value" },
                        order: 1,
                        required_to_create: false,
                        required_to_create_for_contacts: false,
                        visible_on_create: false,
                        visible_to_contacts: false,
                        default: true,
                        ticket_type_id: 42,
                        archived: false,
                    },
                ],
            },
            ticket_states: {
                type: "list",
                data: [
                    {
                        type: "ticket_state",
                        id: "8353",
                        category: "submitted",
                        internal_label: "Submitted",
                        external_label: "Submitted",
                    },
                    {
                        type: "ticket_state",
                        id: "8354",
                        category: "in_progress",
                        internal_label: "In progress",
                        external_label: "In progress",
                    },
                    {
                        type: "ticket_state",
                        id: "8355",
                        category: "waiting_on_customer",
                        internal_label: "Waiting on customer",
                        external_label: "Waiting on you",
                    },
                    {
                        type: "ticket_state",
                        id: "8356",
                        category: "resolved",
                        internal_label: "Resolved",
                        external_label: "Resolved",
                    },
                ],
            },
            archived: false,
            created_at: 1734537870,
            updated_at: 1734537870,
        };
        server.mockEndpoint().get("/ticket_types/id").respondWith().statusCode(200).jsonBody(rawResponseBody).build();

        const response = await client.unstable.ticketTypes.getTicketType({
            id: "id",
        });
        expect(response).toEqual({
            type: "ticket_type",
            id: "72",
            category: "Customer",
            name: "Bug Report",
            description: "Bug Report Template",
            icon: "\uD83C\uDF9F\uFE0F",
            workspace_id: "this_is_an_id656_that_should_be_at_least_",
            ticket_type_attributes: {
                type: "list",
                ticket_type_attributes: [
                    {
                        type: "ticket_type_attribute",
                        id: "1",
                        workspace_id: "ecahpwf5",
                        name: "Title",
                        description: "Bug title.",
                        data_type: "string",
                        input_options: {
                            key: "value",
                        },
                        order: 1,
                        required_to_create: false,
                        required_to_create_for_contacts: false,
                        visible_on_create: false,
                        visible_to_contacts: false,
                        default: true,
                        ticket_type_id: 42,
                        archived: false,
                    },
                ],
            },
            ticket_states: {
                type: "list",
                data: [
                    {
                        type: "ticket_state",
                        id: "8353",
                        category: "submitted",
                        internal_label: "Submitted",
                        external_label: "Submitted",
                    },
                    {
                        type: "ticket_state",
                        id: "8354",
                        category: "in_progress",
                        internal_label: "In progress",
                        external_label: "In progress",
                    },
                    {
                        type: "ticket_state",
                        id: "8355",
                        category: "waiting_on_customer",
                        internal_label: "Waiting on customer",
                        external_label: "Waiting on you",
                    },
                    {
                        type: "ticket_state",
                        id: "8356",
                        category: "resolved",
                        internal_label: "Resolved",
                        external_label: "Resolved",
                    },
                ],
            },
            archived: false,
            created_at: 1734537870,
            updated_at: 1734537870,
        });
    });

    test("getTicketType (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("/ticket_types/id").respondWith().statusCode(401).jsonBody(rawResponseBody).build();

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