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

import { VapiClient } from "../../src/Client";
import { mockServerPool } from "../mock-server/MockServerPool";

describe("ToolsClient", () => {
    test("list", async () => {
        const server = mockServerPool.createServer();
        const client = new VapiClient({ maxRetries: 0, token: "test", environment: server.baseUrl });

        const rawResponseBody = [
            {
                type: "apiRequest",
                messages: [{ type: "request-start", blocking: false }],
                method: "POST",
                timeoutSeconds: 20,
                credentialId: "550e8400-e29b-41d4-a716-446655440000",
                encryptedPaths: ["encryptedPaths"],
                parameters: [{ key: "key", value: "value" }],
                id: "id",
                orgId: "orgId",
                createdAt: "2024-01-15T09:30:00Z",
                updatedAt: "2024-01-15T09:30:00Z",
                rejectionPlan: {
                    conditions: [
                        {
                            type: "regex",
                            regex: "\\\\b(cancel|stop|wait)\\\\b - Matches whole words",
                            target: { position: -1 },
                        },
                    ],
                },
                name: "name",
                description: "description",
                url: "url",
                body: {
                    type: "string",
                    description: "description",
                    pattern: "pattern",
                    format: "date-time",
                    required: ["required"],
                    enum: ["enum"],
                    title: "title",
                },
                headers: {
                    type: "string",
                    description: "description",
                    pattern: "pattern",
                    format: "date-time",
                    required: ["required"],
                    enum: ["enum"],
                    title: "title",
                },
                backoffPlan: {
                    type: { key: "value" },
                    maxRetries: 0,
                    baseDelaySeconds: 1,
                    excludedStatusCodes: [{ key: "value" }, { key: "value" }, { key: "value" }, { key: "value" }],
                },
                variableExtractionPlan: { schema: { type: "string" }, aliases: [{ key: "key", value: "value" }] },
            },
        ];

        server.mockEndpoint().get("/tool").respondWith().statusCode(200).jsonBody(rawResponseBody).build();

        const response = await client.tools.list();
        expect(response).toEqual([
            {
                type: "apiRequest",
                messages: [
                    {
                        type: "request-start",
                        blocking: false,
                    },
                ],
                method: "POST",
                timeoutSeconds: 20,
                credentialId: "550e8400-e29b-41d4-a716-446655440000",
                encryptedPaths: ["encryptedPaths"],
                parameters: [
                    {
                        key: "key",
                        value: "value",
                    },
                ],
                id: "id",
                orgId: "orgId",
                createdAt: "2024-01-15T09:30:00Z",
                updatedAt: "2024-01-15T09:30:00Z",
                rejectionPlan: {
                    conditions: [
                        {
                            type: "regex",
                            regex: "\\\\b(cancel|stop|wait)\\\\b - Matches whole words",
                            target: {
                                position: -1,
                            },
                        },
                    ],
                },
                name: "name",
                description: "description",
                url: "url",
                body: {
                    type: "string",
                    description: "description",
                    pattern: "pattern",
                    format: "date-time",
                    required: ["required"],
                    enum: ["enum"],
                    title: "title",
                },
                headers: {
                    type: "string",
                    description: "description",
                    pattern: "pattern",
                    format: "date-time",
                    required: ["required"],
                    enum: ["enum"],
                    title: "title",
                },
                backoffPlan: {
                    type: {
                        key: "value",
                    },
                    maxRetries: 0,
                    baseDelaySeconds: 1,
                    excludedStatusCodes: [
                        {
                            key: "value",
                        },
                        {
                            key: "value",
                        },
                        {
                            key: "value",
                        },
                        {
                            key: "value",
                        },
                    ],
                },
                variableExtractionPlan: {
                    schema: {
                        type: "string",
                    },
                    aliases: [
                        {
                            key: "key",
                            value: "value",
                        },
                    ],
                },
            },
        ]);
    });

    test("create", async () => {
        const server = mockServerPool.createServer();
        const client = new VapiClient({ maxRetries: 0, token: "test", environment: server.baseUrl });
        const rawRequestBody = { type: "apiRequest", method: "POST", url: "url" };
        const rawResponseBody = {
            type: "apiRequest",
            messages: [
                {
                    type: "request-start",
                    contents: [{ type: "text", text: "text", language: "aa" }],
                    blocking: false,
                    content: "content",
                    conditions: [{ operator: "eq", param: "param", value: "value" }],
                },
            ],
            method: "POST",
            timeoutSeconds: 20,
            credentialId: "550e8400-e29b-41d4-a716-446655440000",
            encryptedPaths: ["encryptedPaths"],
            parameters: [{ key: "key", value: "value" }],
            id: "id",
            orgId: "orgId",
            createdAt: "2024-01-15T09:30:00Z",
            updatedAt: "2024-01-15T09:30:00Z",
            rejectionPlan: {
                conditions: [
                    {
                        type: "regex",
                        regex: "\\\\b(cancel|stop|wait)\\\\b - Matches whole words",
                        target: { position: -1 },
                    },
                ],
            },
            name: "name",
            description: "description",
            url: "url",
            body: {
                type: "string",
                description: "description",
                pattern: "pattern",
                format: "date-time",
                required: ["required"],
                enum: ["enum"],
                title: "title",
            },
            headers: {
                type: "string",
                description: "description",
                pattern: "pattern",
                format: "date-time",
                required: ["required"],
                enum: ["enum"],
                title: "title",
            },
            backoffPlan: {
                type: { key: "value" },
                maxRetries: 0,
                baseDelaySeconds: 1,
                excludedStatusCodes: [{ key: "value" }, { key: "value" }, { key: "value" }, { key: "value" }],
            },
            variableExtractionPlan: {
                schema: {
                    type: "string",
                    description: "description",
                    pattern: "pattern",
                    format: "date-time",
                    required: ["required"],
                    enum: ["enum"],
                    title: "title",
                },
                aliases: [{ key: "key", value: "value" }],
            },
        };

        server
            .mockEndpoint()
            .post("/tool")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.tools.create({
            type: "apiRequest",
            method: "POST",
            url: "url",
        });
        expect(response).toEqual({
            type: "apiRequest",
            messages: [
                {
                    type: "request-start",
                    contents: [
                        {
                            type: "text",
                            text: "text",
                            language: "aa",
                        },
                    ],
                    blocking: false,
                    content: "content",
                    conditions: [
                        {
                            operator: "eq",
                            param: "param",
                            value: "value",
                        },
                    ],
                },
            ],
            method: "POST",
            timeoutSeconds: 20,
            credentialId: "550e8400-e29b-41d4-a716-446655440000",
            encryptedPaths: ["encryptedPaths"],
            parameters: [
                {
                    key: "key",
                    value: "value",
                },
            ],
            id: "id",
            orgId: "orgId",
            createdAt: "2024-01-15T09:30:00Z",
            updatedAt: "2024-01-15T09:30:00Z",
            rejectionPlan: {
                conditions: [
                    {
                        type: "regex",
                        regex: "\\\\b(cancel|stop|wait)\\\\b - Matches whole words",
                        target: {
                            position: -1,
                        },
                    },
                ],
            },
            name: "name",
            description: "description",
            url: "url",
            body: {
                type: "string",
                description: "description",
                pattern: "pattern",
                format: "date-time",
                required: ["required"],
                enum: ["enum"],
                title: "title",
            },
            headers: {
                type: "string",
                description: "description",
                pattern: "pattern",
                format: "date-time",
                required: ["required"],
                enum: ["enum"],
                title: "title",
            },
            backoffPlan: {
                type: {
                    key: "value",
                },
                maxRetries: 0,
                baseDelaySeconds: 1,
                excludedStatusCodes: [
                    {
                        key: "value",
                    },
                    {
                        key: "value",
                    },
                    {
                        key: "value",
                    },
                    {
                        key: "value",
                    },
                ],
            },
            variableExtractionPlan: {
                schema: {
                    type: "string",
                    description: "description",
                    pattern: "pattern",
                    format: "date-time",
                    required: ["required"],
                    enum: ["enum"],
                    title: "title",
                },
                aliases: [
                    {
                        key: "key",
                        value: "value",
                    },
                ],
            },
        });
    });

    test("get", async () => {
        const server = mockServerPool.createServer();
        const client = new VapiClient({ maxRetries: 0, token: "test", environment: server.baseUrl });

        const rawResponseBody = {
            type: "apiRequest",
            messages: [
                {
                    type: "request-start",
                    contents: [{ type: "text", text: "text", language: "aa" }],
                    blocking: false,
                    content: "content",
                    conditions: [{ operator: "eq", param: "param", value: "value" }],
                },
            ],
            method: "POST",
            timeoutSeconds: 20,
            credentialId: "550e8400-e29b-41d4-a716-446655440000",
            encryptedPaths: ["encryptedPaths"],
            parameters: [{ key: "key", value: "value" }],
            id: "id",
            orgId: "orgId",
            createdAt: "2024-01-15T09:30:00Z",
            updatedAt: "2024-01-15T09:30:00Z",
            rejectionPlan: {
                conditions: [
                    {
                        type: "regex",
                        regex: "\\\\b(cancel|stop|wait)\\\\b - Matches whole words",
                        target: { position: -1 },
                    },
                ],
            },
            name: "name",
            description: "description",
            url: "url",
            body: {
                type: "string",
                description: "description",
                pattern: "pattern",
                format: "date-time",
                required: ["required"],
                enum: ["enum"],
                title: "title",
            },
            headers: {
                type: "string",
                description: "description",
                pattern: "pattern",
                format: "date-time",
                required: ["required"],
                enum: ["enum"],
                title: "title",
            },
            backoffPlan: {
                type: { key: "value" },
                maxRetries: 0,
                baseDelaySeconds: 1,
                excludedStatusCodes: [{ key: "value" }, { key: "value" }, { key: "value" }, { key: "value" }],
            },
            variableExtractionPlan: {
                schema: {
                    type: "string",
                    description: "description",
                    pattern: "pattern",
                    format: "date-time",
                    required: ["required"],
                    enum: ["enum"],
                    title: "title",
                },
                aliases: [{ key: "key", value: "value" }],
            },
        };

        server.mockEndpoint().get("/tool/id").respondWith().statusCode(200).jsonBody(rawResponseBody).build();

        const response = await client.tools.get({
            id: "id",
        });
        expect(response).toEqual({
            type: "apiRequest",
            messages: [
                {
                    type: "request-start",
                    contents: [
                        {
                            type: "text",
                            text: "text",
                            language: "aa",
                        },
                    ],
                    blocking: false,
                    content: "content",
                    conditions: [
                        {
                            operator: "eq",
                            param: "param",
                            value: "value",
                        },
                    ],
                },
            ],
            method: "POST",
            timeoutSeconds: 20,
            credentialId: "550e8400-e29b-41d4-a716-446655440000",
            encryptedPaths: ["encryptedPaths"],
            parameters: [
                {
                    key: "key",
                    value: "value",
                },
            ],
            id: "id",
            orgId: "orgId",
            createdAt: "2024-01-15T09:30:00Z",
            updatedAt: "2024-01-15T09:30:00Z",
            rejectionPlan: {
                conditions: [
                    {
                        type: "regex",
                        regex: "\\\\b(cancel|stop|wait)\\\\b - Matches whole words",
                        target: {
                            position: -1,
                        },
                    },
                ],
            },
            name: "name",
            description: "description",
            url: "url",
            body: {
                type: "string",
                description: "description",
                pattern: "pattern",
                format: "date-time",
                required: ["required"],
                enum: ["enum"],
                title: "title",
            },
            headers: {
                type: "string",
                description: "description",
                pattern: "pattern",
                format: "date-time",
                required: ["required"],
                enum: ["enum"],
                title: "title",
            },
            backoffPlan: {
                type: {
                    key: "value",
                },
                maxRetries: 0,
                baseDelaySeconds: 1,
                excludedStatusCodes: [
                    {
                        key: "value",
                    },
                    {
                        key: "value",
                    },
                    {
                        key: "value",
                    },
                    {
                        key: "value",
                    },
                ],
            },
            variableExtractionPlan: {
                schema: {
                    type: "string",
                    description: "description",
                    pattern: "pattern",
                    format: "date-time",
                    required: ["required"],
                    enum: ["enum"],
                    title: "title",
                },
                aliases: [
                    {
                        key: "key",
                        value: "value",
                    },
                ],
            },
        });
    });

    test("delete", async () => {
        const server = mockServerPool.createServer();
        const client = new VapiClient({ maxRetries: 0, token: "test", environment: server.baseUrl });

        const rawResponseBody = {
            type: "apiRequest",
            messages: [
                {
                    type: "request-start",
                    contents: [{ type: "text", text: "text", language: "aa" }],
                    blocking: false,
                    content: "content",
                    conditions: [{ operator: "eq", param: "param", value: "value" }],
                },
            ],
            method: "POST",
            timeoutSeconds: 20,
            credentialId: "550e8400-e29b-41d4-a716-446655440000",
            encryptedPaths: ["encryptedPaths"],
            parameters: [{ key: "key", value: "value" }],
            id: "id",
            orgId: "orgId",
            createdAt: "2024-01-15T09:30:00Z",
            updatedAt: "2024-01-15T09:30:00Z",
            rejectionPlan: {
                conditions: [
                    {
                        type: "regex",
                        regex: "\\\\b(cancel|stop|wait)\\\\b - Matches whole words",
                        target: { position: -1 },
                    },
                ],
            },
            name: "name",
            description: "description",
            url: "url",
            body: {
                type: "string",
                description: "description",
                pattern: "pattern",
                format: "date-time",
                required: ["required"],
                enum: ["enum"],
                title: "title",
            },
            headers: {
                type: "string",
                description: "description",
                pattern: "pattern",
                format: "date-time",
                required: ["required"],
                enum: ["enum"],
                title: "title",
            },
            backoffPlan: {
                type: { key: "value" },
                maxRetries: 0,
                baseDelaySeconds: 1,
                excludedStatusCodes: [{ key: "value" }, { key: "value" }, { key: "value" }, { key: "value" }],
            },
            variableExtractionPlan: {
                schema: {
                    type: "string",
                    description: "description",
                    pattern: "pattern",
                    format: "date-time",
                    required: ["required"],
                    enum: ["enum"],
                    title: "title",
                },
                aliases: [{ key: "key", value: "value" }],
            },
        };

        server.mockEndpoint().delete("/tool/id").respondWith().statusCode(200).jsonBody(rawResponseBody).build();

        const response = await client.tools.delete({
            id: "id",
        });
        expect(response).toEqual({
            type: "apiRequest",
            messages: [
                {
                    type: "request-start",
                    contents: [
                        {
                            type: "text",
                            text: "text",
                            language: "aa",
                        },
                    ],
                    blocking: false,
                    content: "content",
                    conditions: [
                        {
                            operator: "eq",
                            param: "param",
                            value: "value",
                        },
                    ],
                },
            ],
            method: "POST",
            timeoutSeconds: 20,
            credentialId: "550e8400-e29b-41d4-a716-446655440000",
            encryptedPaths: ["encryptedPaths"],
            parameters: [
                {
                    key: "key",
                    value: "value",
                },
            ],
            id: "id",
            orgId: "orgId",
            createdAt: "2024-01-15T09:30:00Z",
            updatedAt: "2024-01-15T09:30:00Z",
            rejectionPlan: {
                conditions: [
                    {
                        type: "regex",
                        regex: "\\\\b(cancel|stop|wait)\\\\b - Matches whole words",
                        target: {
                            position: -1,
                        },
                    },
                ],
            },
            name: "name",
            description: "description",
            url: "url",
            body: {
                type: "string",
                description: "description",
                pattern: "pattern",
                format: "date-time",
                required: ["required"],
                enum: ["enum"],
                title: "title",
            },
            headers: {
                type: "string",
                description: "description",
                pattern: "pattern",
                format: "date-time",
                required: ["required"],
                enum: ["enum"],
                title: "title",
            },
            backoffPlan: {
                type: {
                    key: "value",
                },
                maxRetries: 0,
                baseDelaySeconds: 1,
                excludedStatusCodes: [
                    {
                        key: "value",
                    },
                    {
                        key: "value",
                    },
                    {
                        key: "value",
                    },
                    {
                        key: "value",
                    },
                ],
            },
            variableExtractionPlan: {
                schema: {
                    type: "string",
                    description: "description",
                    pattern: "pattern",
                    format: "date-time",
                    required: ["required"],
                    enum: ["enum"],
                    title: "title",
                },
                aliases: [
                    {
                        key: "key",
                        value: "value",
                    },
                ],
            },
        });
    });

    test("update", async () => {
        const server = mockServerPool.createServer();
        const client = new VapiClient({ maxRetries: 0, token: "test", environment: server.baseUrl });
        const rawRequestBody = { type: "apiRequest" };
        const rawResponseBody = {
            type: "apiRequest",
            messages: [
                {
                    type: "request-start",
                    contents: [{ type: "text", text: "text", language: "aa" }],
                    blocking: false,
                    content: "content",
                    conditions: [{ operator: "eq", param: "param", value: "value" }],
                },
            ],
            method: "POST",
            timeoutSeconds: 20,
            credentialId: "550e8400-e29b-41d4-a716-446655440000",
            encryptedPaths: ["encryptedPaths"],
            parameters: [{ key: "key", value: "value" }],
            id: "id",
            orgId: "orgId",
            createdAt: "2024-01-15T09:30:00Z",
            updatedAt: "2024-01-15T09:30:00Z",
            rejectionPlan: {
                conditions: [
                    {
                        type: "regex",
                        regex: "\\\\b(cancel|stop|wait)\\\\b - Matches whole words",
                        target: { position: -1 },
                    },
                ],
            },
            name: "name",
            description: "description",
            url: "url",
            body: {
                type: "string",
                description: "description",
                pattern: "pattern",
                format: "date-time",
                required: ["required"],
                enum: ["enum"],
                title: "title",
            },
            headers: {
                type: "string",
                description: "description",
                pattern: "pattern",
                format: "date-time",
                required: ["required"],
                enum: ["enum"],
                title: "title",
            },
            backoffPlan: {
                type: { key: "value" },
                maxRetries: 0,
                baseDelaySeconds: 1,
                excludedStatusCodes: [{ key: "value" }, { key: "value" }, { key: "value" }, { key: "value" }],
            },
            variableExtractionPlan: {
                schema: {
                    type: "string",
                    description: "description",
                    pattern: "pattern",
                    format: "date-time",
                    required: ["required"],
                    enum: ["enum"],
                    title: "title",
                },
                aliases: [{ key: "key", value: "value" }],
            },
        };

        server
            .mockEndpoint()
            .patch("/tool/id")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.tools.update({
            id: "id",
            body: {
                type: "apiRequest",
            },
        });
        expect(response).toEqual({
            type: "apiRequest",
            messages: [
                {
                    type: "request-start",
                    contents: [
                        {
                            type: "text",
                            text: "text",
                            language: "aa",
                        },
                    ],
                    blocking: false,
                    content: "content",
                    conditions: [
                        {
                            operator: "eq",
                            param: "param",
                            value: "value",
                        },
                    ],
                },
            ],
            method: "POST",
            timeoutSeconds: 20,
            credentialId: "550e8400-e29b-41d4-a716-446655440000",
            encryptedPaths: ["encryptedPaths"],
            parameters: [
                {
                    key: "key",
                    value: "value",
                },
            ],
            id: "id",
            orgId: "orgId",
            createdAt: "2024-01-15T09:30:00Z",
            updatedAt: "2024-01-15T09:30:00Z",
            rejectionPlan: {
                conditions: [
                    {
                        type: "regex",
                        regex: "\\\\b(cancel|stop|wait)\\\\b - Matches whole words",
                        target: {
                            position: -1,
                        },
                    },
                ],
            },
            name: "name",
            description: "description",
            url: "url",
            body: {
                type: "string",
                description: "description",
                pattern: "pattern",
                format: "date-time",
                required: ["required"],
                enum: ["enum"],
                title: "title",
            },
            headers: {
                type: "string",
                description: "description",
                pattern: "pattern",
                format: "date-time",
                required: ["required"],
                enum: ["enum"],
                title: "title",
            },
            backoffPlan: {
                type: {
                    key: "value",
                },
                maxRetries: 0,
                baseDelaySeconds: 1,
                excludedStatusCodes: [
                    {
                        key: "value",
                    },
                    {
                        key: "value",
                    },
                    {
                        key: "value",
                    },
                    {
                        key: "value",
                    },
                ],
            },
            variableExtractionPlan: {
                schema: {
                    type: "string",
                    description: "description",
                    pattern: "pattern",
                    format: "date-time",
                    required: ["required"],
                    enum: ["enum"],
                    title: "title",
                },
                aliases: [
                    {
                        key: "key",
                        value: "value",
                    },
                ],
            },
        });
    });
});
