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

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

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

        const rawResponseBody = [
            {
                provider: "byo-phone-number",
                fallbackDestination: {
                    type: "number",
                    message: "message",
                    numberE164CheckEnabled: true,
                    number: "number",
                    extension: "extension",
                    callerId: "callerId",
                    transferPlan: { mode: "blind-transfer" },
                    description: "description",
                },
                hooks: [{ on: "call.ringing", do: [{ type: "transfer" }] }],
                numberE164CheckEnabled: true,
                id: "id",
                orgId: "orgId",
                createdAt: "2024-01-15T09:30:00Z",
                updatedAt: "2024-01-15T09:30:00Z",
                status: "active",
                name: "name",
                assistantId: "assistantId",
                workflowId: "workflowId",
                squadId: "squadId",
                server: {
                    timeoutSeconds: 20,
                    credentialId: "550e8400-e29b-41d4-a716-446655440000",
                    staticIpAddressesEnabled: false,
                    encryptedPaths: ["encryptedPaths"],
                    url: "url",
                    headers: { key: "value" },
                    backoffPlan: {
                        type: { key: "value" },
                        maxRetries: 0,
                        baseDelaySeconds: 1,
                        excludedStatusCodes: [{ key: "value" }, { key: "value" }, { key: "value" }, { key: "value" }],
                    },
                },
                number: "number",
                credentialId: "credentialId",
            },
        ];

        server.mockEndpoint().get("/phone-number").respondWith().statusCode(200).jsonBody(rawResponseBody).build();

        const response = await client.phoneNumbers.list();
        expect(response).toEqual([
            {
                provider: "byo-phone-number",
                fallbackDestination: {
                    type: "number",
                    message: "message",
                    numberE164CheckEnabled: true,
                    number: "number",
                    extension: "extension",
                    callerId: "callerId",
                    transferPlan: {
                        mode: "blind-transfer",
                    },
                    description: "description",
                },
                hooks: [
                    {
                        on: "call.ringing",
                        do: [
                            {
                                type: "transfer",
                            },
                        ],
                    },
                ],
                numberE164CheckEnabled: true,
                id: "id",
                orgId: "orgId",
                createdAt: "2024-01-15T09:30:00Z",
                updatedAt: "2024-01-15T09:30:00Z",
                status: "active",
                name: "name",
                assistantId: "assistantId",
                workflowId: "workflowId",
                squadId: "squadId",
                server: {
                    timeoutSeconds: 20,
                    credentialId: "550e8400-e29b-41d4-a716-446655440000",
                    staticIpAddressesEnabled: false,
                    encryptedPaths: ["encryptedPaths"],
                    url: "url",
                    headers: {
                        key: "value",
                    },
                    backoffPlan: {
                        type: {
                            key: "value",
                        },
                        maxRetries: 0,
                        baseDelaySeconds: 1,
                        excludedStatusCodes: [
                            {
                                key: "value",
                            },
                            {
                                key: "value",
                            },
                            {
                                key: "value",
                            },
                            {
                                key: "value",
                            },
                        ],
                    },
                },
                number: "number",
                credentialId: "credentialId",
            },
        ]);
    });

    test("create", async () => {
        const server = mockServerPool.createServer();
        const client = new VapiClient({ maxRetries: 0, token: "test", environment: server.baseUrl });
        const rawRequestBody = { provider: "byo-phone-number", credentialId: "credentialId" };
        const rawResponseBody = {
            provider: "byo-phone-number",
            fallbackDestination: {
                type: "number",
                message: "message",
                numberE164CheckEnabled: true,
                number: "number",
                extension: "extension",
                callerId: "callerId",
                transferPlan: {
                    mode: "blind-transfer",
                    message: "message",
                    timeout: 1.1,
                    sipVerb: { key: "value" },
                    dialTimeout: 1.1,
                    holdAudioUrl: "holdAudioUrl",
                    transferCompleteAudioUrl: "transferCompleteAudioUrl",
                    contextEngineeringPlan: { type: "lastNMessages", maxMessages: 1.1 },
                    twiml: "twiml",
                    sipHeadersInReferToEnabled: true,
                    fallbackPlan: { message: "message" },
                },
                description: "description",
            },
            hooks: [
                {
                    on: "call.ringing",
                    filters: [{ type: "startsWith", key: "number", startsWith: ["91", "86", "7"] }],
                    do: [{ type: "transfer" }],
                },
            ],
            numberE164CheckEnabled: true,
            id: "id",
            orgId: "orgId",
            createdAt: "2024-01-15T09:30:00Z",
            updatedAt: "2024-01-15T09:30:00Z",
            status: "active",
            name: "name",
            assistantId: "assistantId",
            workflowId: "workflowId",
            squadId: "squadId",
            server: {
                timeoutSeconds: 20,
                credentialId: "550e8400-e29b-41d4-a716-446655440000",
                staticIpAddressesEnabled: false,
                encryptedPaths: ["encryptedPaths"],
                url: "url",
                headers: { key: "value" },
                backoffPlan: {
                    type: { key: "value" },
                    maxRetries: 0,
                    baseDelaySeconds: 1,
                    excludedStatusCodes: [{ key: "value" }, { key: "value" }, { key: "value" }, { key: "value" }],
                },
            },
            number: "number",
            credentialId: "credentialId",
        };

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

        const response = await client.phoneNumbers.create({
            provider: "byo-phone-number",
            credentialId: "credentialId",
        });
        expect(response).toEqual({
            provider: "byo-phone-number",
            fallbackDestination: {
                type: "number",
                message: "message",
                numberE164CheckEnabled: true,
                number: "number",
                extension: "extension",
                callerId: "callerId",
                transferPlan: {
                    mode: "blind-transfer",
                    message: "message",
                    timeout: 1.1,
                    sipVerb: {
                        key: "value",
                    },
                    dialTimeout: 1.1,
                    holdAudioUrl: "holdAudioUrl",
                    transferCompleteAudioUrl: "transferCompleteAudioUrl",
                    contextEngineeringPlan: {
                        type: "lastNMessages",
                        maxMessages: 1.1,
                    },
                    twiml: "twiml",
                    sipHeadersInReferToEnabled: true,
                    fallbackPlan: {
                        message: "message",
                    },
                },
                description: "description",
            },
            hooks: [
                {
                    on: "call.ringing",
                    filters: [
                        {
                            type: "startsWith",
                            key: "number",
                            startsWith: ["91", "86", "7"],
                        },
                    ],
                    do: [
                        {
                            type: "transfer",
                        },
                    ],
                },
            ],
            numberE164CheckEnabled: true,
            id: "id",
            orgId: "orgId",
            createdAt: "2024-01-15T09:30:00Z",
            updatedAt: "2024-01-15T09:30:00Z",
            status: "active",
            name: "name",
            assistantId: "assistantId",
            workflowId: "workflowId",
            squadId: "squadId",
            server: {
                timeoutSeconds: 20,
                credentialId: "550e8400-e29b-41d4-a716-446655440000",
                staticIpAddressesEnabled: false,
                encryptedPaths: ["encryptedPaths"],
                url: "url",
                headers: {
                    key: "value",
                },
                backoffPlan: {
                    type: {
                        key: "value",
                    },
                    maxRetries: 0,
                    baseDelaySeconds: 1,
                    excludedStatusCodes: [
                        {
                            key: "value",
                        },
                        {
                            key: "value",
                        },
                        {
                            key: "value",
                        },
                        {
                            key: "value",
                        },
                    ],
                },
            },
            number: "number",
            credentialId: "credentialId",
        });
    });

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

        const rawResponseBody = {
            results: [
                {
                    provider: "byo-phone-number",
                    fallbackDestination: { type: "number", number: "number" },
                    hooks: [{ on: "call.ringing", do: [{ type: "transfer" }] }],
                    numberE164CheckEnabled: true,
                    id: "id",
                    orgId: "orgId",
                    createdAt: "2024-01-15T09:30:00Z",
                    updatedAt: "2024-01-15T09:30:00Z",
                    status: "active",
                    name: "name",
                    assistantId: "assistantId",
                    workflowId: "workflowId",
                    squadId: "squadId",
                    server: {
                        timeoutSeconds: 20,
                        credentialId: "550e8400-e29b-41d4-a716-446655440000",
                        staticIpAddressesEnabled: false,
                        backoffPlan: {
                            type: { key: "value" },
                            maxRetries: 0,
                            baseDelaySeconds: 1,
                            excludedStatusCodes: [
                                { key: "value" },
                                { key: "value" },
                                { key: "value" },
                                { key: "value" },
                            ],
                        },
                    },
                    number: "number",
                    credentialId: "credentialId",
                },
            ],
            metadata: {
                itemsPerPage: 1.1,
                totalItems: 1.1,
                currentPage: 1.1,
                itemsBeyondRetention: true,
                createdAtLe: "2024-01-15T09:30:00Z",
                createdAtGe: "2024-01-15T09:30:00Z",
            },
        };

        server.mockEndpoint().get("/v2/phone-number").respondWith().statusCode(200).jsonBody(rawResponseBody).build();

        const response = await client.phoneNumbers.phoneNumberControllerFindAllPaginated();
        expect(response).toEqual({
            results: [
                {
                    provider: "byo-phone-number",
                    fallbackDestination: {
                        type: "number",
                        number: "number",
                    },
                    hooks: [
                        {
                            on: "call.ringing",
                            do: [
                                {
                                    type: "transfer",
                                },
                            ],
                        },
                    ],
                    numberE164CheckEnabled: true,
                    id: "id",
                    orgId: "orgId",
                    createdAt: "2024-01-15T09:30:00Z",
                    updatedAt: "2024-01-15T09:30:00Z",
                    status: "active",
                    name: "name",
                    assistantId: "assistantId",
                    workflowId: "workflowId",
                    squadId: "squadId",
                    server: {
                        timeoutSeconds: 20,
                        credentialId: "550e8400-e29b-41d4-a716-446655440000",
                        staticIpAddressesEnabled: false,
                        backoffPlan: {
                            type: {
                                key: "value",
                            },
                            maxRetries: 0,
                            baseDelaySeconds: 1,
                            excludedStatusCodes: [
                                {
                                    key: "value",
                                },
                                {
                                    key: "value",
                                },
                                {
                                    key: "value",
                                },
                                {
                                    key: "value",
                                },
                            ],
                        },
                    },
                    number: "number",
                    credentialId: "credentialId",
                },
            ],
            metadata: {
                itemsPerPage: 1.1,
                totalItems: 1.1,
                currentPage: 1.1,
                itemsBeyondRetention: true,
                createdAtLe: "2024-01-15T09:30:00Z",
                createdAtGe: "2024-01-15T09:30:00Z",
            },
        });
    });

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

        const rawResponseBody = {
            provider: "byo-phone-number",
            fallbackDestination: {
                type: "number",
                message: "message",
                numberE164CheckEnabled: true,
                number: "number",
                extension: "extension",
                callerId: "callerId",
                transferPlan: {
                    mode: "blind-transfer",
                    message: "message",
                    timeout: 1.1,
                    sipVerb: { key: "value" },
                    dialTimeout: 1.1,
                    holdAudioUrl: "holdAudioUrl",
                    transferCompleteAudioUrl: "transferCompleteAudioUrl",
                    contextEngineeringPlan: { type: "lastNMessages", maxMessages: 1.1 },
                    twiml: "twiml",
                    sipHeadersInReferToEnabled: true,
                    fallbackPlan: { message: "message" },
                },
                description: "description",
            },
            hooks: [
                {
                    on: "call.ringing",
                    filters: [{ type: "startsWith", key: "number", startsWith: ["91", "86", "7"] }],
                    do: [{ type: "transfer" }],
                },
            ],
            numberE164CheckEnabled: true,
            id: "id",
            orgId: "orgId",
            createdAt: "2024-01-15T09:30:00Z",
            updatedAt: "2024-01-15T09:30:00Z",
            status: "active",
            name: "name",
            assistantId: "assistantId",
            workflowId: "workflowId",
            squadId: "squadId",
            server: {
                timeoutSeconds: 20,
                credentialId: "550e8400-e29b-41d4-a716-446655440000",
                staticIpAddressesEnabled: false,
                encryptedPaths: ["encryptedPaths"],
                url: "url",
                headers: { key: "value" },
                backoffPlan: {
                    type: { key: "value" },
                    maxRetries: 0,
                    baseDelaySeconds: 1,
                    excludedStatusCodes: [{ key: "value" }, { key: "value" }, { key: "value" }, { key: "value" }],
                },
            },
            number: "number",
            credentialId: "credentialId",
        };

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

        const response = await client.phoneNumbers.get({
            id: "id",
        });
        expect(response).toEqual({
            provider: "byo-phone-number",
            fallbackDestination: {
                type: "number",
                message: "message",
                numberE164CheckEnabled: true,
                number: "number",
                extension: "extension",
                callerId: "callerId",
                transferPlan: {
                    mode: "blind-transfer",
                    message: "message",
                    timeout: 1.1,
                    sipVerb: {
                        key: "value",
                    },
                    dialTimeout: 1.1,
                    holdAudioUrl: "holdAudioUrl",
                    transferCompleteAudioUrl: "transferCompleteAudioUrl",
                    contextEngineeringPlan: {
                        type: "lastNMessages",
                        maxMessages: 1.1,
                    },
                    twiml: "twiml",
                    sipHeadersInReferToEnabled: true,
                    fallbackPlan: {
                        message: "message",
                    },
                },
                description: "description",
            },
            hooks: [
                {
                    on: "call.ringing",
                    filters: [
                        {
                            type: "startsWith",
                            key: "number",
                            startsWith: ["91", "86", "7"],
                        },
                    ],
                    do: [
                        {
                            type: "transfer",
                        },
                    ],
                },
            ],
            numberE164CheckEnabled: true,
            id: "id",
            orgId: "orgId",
            createdAt: "2024-01-15T09:30:00Z",
            updatedAt: "2024-01-15T09:30:00Z",
            status: "active",
            name: "name",
            assistantId: "assistantId",
            workflowId: "workflowId",
            squadId: "squadId",
            server: {
                timeoutSeconds: 20,
                credentialId: "550e8400-e29b-41d4-a716-446655440000",
                staticIpAddressesEnabled: false,
                encryptedPaths: ["encryptedPaths"],
                url: "url",
                headers: {
                    key: "value",
                },
                backoffPlan: {
                    type: {
                        key: "value",
                    },
                    maxRetries: 0,
                    baseDelaySeconds: 1,
                    excludedStatusCodes: [
                        {
                            key: "value",
                        },
                        {
                            key: "value",
                        },
                        {
                            key: "value",
                        },
                        {
                            key: "value",
                        },
                    ],
                },
            },
            number: "number",
            credentialId: "credentialId",
        });
    });

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

        const rawResponseBody = {
            provider: "byo-phone-number",
            fallbackDestination: {
                type: "number",
                message: "message",
                numberE164CheckEnabled: true,
                number: "number",
                extension: "extension",
                callerId: "callerId",
                transferPlan: {
                    mode: "blind-transfer",
                    message: "message",
                    timeout: 1.1,
                    sipVerb: { key: "value" },
                    dialTimeout: 1.1,
                    holdAudioUrl: "holdAudioUrl",
                    transferCompleteAudioUrl: "transferCompleteAudioUrl",
                    contextEngineeringPlan: { type: "lastNMessages", maxMessages: 1.1 },
                    twiml: "twiml",
                    sipHeadersInReferToEnabled: true,
                    fallbackPlan: { message: "message" },
                },
                description: "description",
            },
            hooks: [
                {
                    on: "call.ringing",
                    filters: [{ type: "startsWith", key: "number", startsWith: ["91", "86", "7"] }],
                    do: [{ type: "transfer" }],
                },
            ],
            numberE164CheckEnabled: true,
            id: "id",
            orgId: "orgId",
            createdAt: "2024-01-15T09:30:00Z",
            updatedAt: "2024-01-15T09:30:00Z",
            status: "active",
            name: "name",
            assistantId: "assistantId",
            workflowId: "workflowId",
            squadId: "squadId",
            server: {
                timeoutSeconds: 20,
                credentialId: "550e8400-e29b-41d4-a716-446655440000",
                staticIpAddressesEnabled: false,
                encryptedPaths: ["encryptedPaths"],
                url: "url",
                headers: { key: "value" },
                backoffPlan: {
                    type: { key: "value" },
                    maxRetries: 0,
                    baseDelaySeconds: 1,
                    excludedStatusCodes: [{ key: "value" }, { key: "value" }, { key: "value" }, { key: "value" }],
                },
            },
            number: "number",
            credentialId: "credentialId",
        };

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

        const response = await client.phoneNumbers.delete({
            id: "id",
        });
        expect(response).toEqual({
            provider: "byo-phone-number",
            fallbackDestination: {
                type: "number",
                message: "message",
                numberE164CheckEnabled: true,
                number: "number",
                extension: "extension",
                callerId: "callerId",
                transferPlan: {
                    mode: "blind-transfer",
                    message: "message",
                    timeout: 1.1,
                    sipVerb: {
                        key: "value",
                    },
                    dialTimeout: 1.1,
                    holdAudioUrl: "holdAudioUrl",
                    transferCompleteAudioUrl: "transferCompleteAudioUrl",
                    contextEngineeringPlan: {
                        type: "lastNMessages",
                        maxMessages: 1.1,
                    },
                    twiml: "twiml",
                    sipHeadersInReferToEnabled: true,
                    fallbackPlan: {
                        message: "message",
                    },
                },
                description: "description",
            },
            hooks: [
                {
                    on: "call.ringing",
                    filters: [
                        {
                            type: "startsWith",
                            key: "number",
                            startsWith: ["91", "86", "7"],
                        },
                    ],
                    do: [
                        {
                            type: "transfer",
                        },
                    ],
                },
            ],
            numberE164CheckEnabled: true,
            id: "id",
            orgId: "orgId",
            createdAt: "2024-01-15T09:30:00Z",
            updatedAt: "2024-01-15T09:30:00Z",
            status: "active",
            name: "name",
            assistantId: "assistantId",
            workflowId: "workflowId",
            squadId: "squadId",
            server: {
                timeoutSeconds: 20,
                credentialId: "550e8400-e29b-41d4-a716-446655440000",
                staticIpAddressesEnabled: false,
                encryptedPaths: ["encryptedPaths"],
                url: "url",
                headers: {
                    key: "value",
                },
                backoffPlan: {
                    type: {
                        key: "value",
                    },
                    maxRetries: 0,
                    baseDelaySeconds: 1,
                    excludedStatusCodes: [
                        {
                            key: "value",
                        },
                        {
                            key: "value",
                        },
                        {
                            key: "value",
                        },
                        {
                            key: "value",
                        },
                    ],
                },
            },
            number: "number",
            credentialId: "credentialId",
        });
    });

    test("update", async () => {
        const server = mockServerPool.createServer();
        const client = new VapiClient({ maxRetries: 0, token: "test", environment: server.baseUrl });
        const rawRequestBody = { provider: "byo-phone-number" };
        const rawResponseBody = {
            provider: "byo-phone-number",
            fallbackDestination: {
                type: "number",
                message: "message",
                numberE164CheckEnabled: true,
                number: "number",
                extension: "extension",
                callerId: "callerId",
                transferPlan: {
                    mode: "blind-transfer",
                    message: "message",
                    timeout: 1.1,
                    sipVerb: { key: "value" },
                    dialTimeout: 1.1,
                    holdAudioUrl: "holdAudioUrl",
                    transferCompleteAudioUrl: "transferCompleteAudioUrl",
                    contextEngineeringPlan: { type: "lastNMessages", maxMessages: 1.1 },
                    twiml: "twiml",
                    sipHeadersInReferToEnabled: true,
                    fallbackPlan: { message: "message" },
                },
                description: "description",
            },
            hooks: [
                {
                    on: "call.ringing",
                    filters: [{ type: "startsWith", key: "number", startsWith: ["91", "86", "7"] }],
                    do: [{ type: "transfer" }],
                },
            ],
            numberE164CheckEnabled: true,
            id: "id",
            orgId: "orgId",
            createdAt: "2024-01-15T09:30:00Z",
            updatedAt: "2024-01-15T09:30:00Z",
            status: "active",
            name: "name",
            assistantId: "assistantId",
            workflowId: "workflowId",
            squadId: "squadId",
            server: {
                timeoutSeconds: 20,
                credentialId: "550e8400-e29b-41d4-a716-446655440000",
                staticIpAddressesEnabled: false,
                encryptedPaths: ["encryptedPaths"],
                url: "url",
                headers: { key: "value" },
                backoffPlan: {
                    type: { key: "value" },
                    maxRetries: 0,
                    baseDelaySeconds: 1,
                    excludedStatusCodes: [{ key: "value" }, { key: "value" }, { key: "value" }, { key: "value" }],
                },
            },
            number: "number",
            credentialId: "credentialId",
        };

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

        const response = await client.phoneNumbers.update({
            id: "id",
            body: {
                provider: "byo-phone-number",
            },
        });
        expect(response).toEqual({
            provider: "byo-phone-number",
            fallbackDestination: {
                type: "number",
                message: "message",
                numberE164CheckEnabled: true,
                number: "number",
                extension: "extension",
                callerId: "callerId",
                transferPlan: {
                    mode: "blind-transfer",
                    message: "message",
                    timeout: 1.1,
                    sipVerb: {
                        key: "value",
                    },
                    dialTimeout: 1.1,
                    holdAudioUrl: "holdAudioUrl",
                    transferCompleteAudioUrl: "transferCompleteAudioUrl",
                    contextEngineeringPlan: {
                        type: "lastNMessages",
                        maxMessages: 1.1,
                    },
                    twiml: "twiml",
                    sipHeadersInReferToEnabled: true,
                    fallbackPlan: {
                        message: "message",
                    },
                },
                description: "description",
            },
            hooks: [
                {
                    on: "call.ringing",
                    filters: [
                        {
                            type: "startsWith",
                            key: "number",
                            startsWith: ["91", "86", "7"],
                        },
                    ],
                    do: [
                        {
                            type: "transfer",
                        },
                    ],
                },
            ],
            numberE164CheckEnabled: true,
            id: "id",
            orgId: "orgId",
            createdAt: "2024-01-15T09:30:00Z",
            updatedAt: "2024-01-15T09:30:00Z",
            status: "active",
            name: "name",
            assistantId: "assistantId",
            workflowId: "workflowId",
            squadId: "squadId",
            server: {
                timeoutSeconds: 20,
                credentialId: "550e8400-e29b-41d4-a716-446655440000",
                staticIpAddressesEnabled: false,
                encryptedPaths: ["encryptedPaths"],
                url: "url",
                headers: {
                    key: "value",
                },
                backoffPlan: {
                    type: {
                        key: "value",
                    },
                    maxRetries: 0,
                    baseDelaySeconds: 1,
                    excludedStatusCodes: [
                        {
                            key: "value",
                        },
                        {
                            key: "value",
                        },
                        {
                            key: "value",
                        },
                        {
                            key: "value",
                        },
                    ],
                },
            },
            number: "number",
            credentialId: "credentialId",
        });
    });
});
