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

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

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

        const rawResponseBody = {
            results: [
                {
                    name: "name",
                    type: "bar",
                    id: "id",
                    orgId: "orgId",
                    createdAt: "2024-01-15T09:30:00Z",
                    updatedAt: "2024-01-15T09:30:00Z",
                },
            ],
            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("/reporting/insight").respondWith().statusCode(200).jsonBody(rawResponseBody).build();

        const response = await client.insight.insightControllerFindAll();
        expect(response).toEqual({
            results: [
                {
                    name: "name",
                    type: "bar",
                    id: "id",
                    orgId: "orgId",
                    createdAt: "2024-01-15T09:30:00Z",
                    updatedAt: "2024-01-15T09:30:00Z",
                },
            ],
            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("InsightController_create", async () => {
        const server = mockServerPool.createServer();
        const client = new VapiClient({ maxRetries: 0, token: "test", environment: server.baseUrl });
        const rawRequestBody = {
            type: "bar",
            queries: [{ type: "vapiql-json", table: "call", column: "id", operation: "count" }],
        };
        const rawResponseBody = {
            type: "bar",
            name: "name",
            formulas: [{ name: "Booking Rate", formula: "formula" }],
            metadata: {
                xAxisLabel: "xAxisLabel",
                yAxisLabel: "yAxisLabel",
                yAxisMin: 1.1,
                yAxisMax: 1.1,
                name: "name",
            },
            timeRange: { step: "minute", start: { key: "value" }, end: { key: "value" }, timezone: "timezone" },
            groupBy: "assistantId",
            queries: [
                {
                    type: "vapiql-json",
                    table: "call",
                    filters: [{ column: "assistantId", operator: "=", value: "value" }],
                    column: "id",
                    operation: "count",
                    name: "Total Calls",
                },
            ],
            id: "id",
            orgId: "orgId",
            createdAt: "2024-01-15T09:30:00Z",
            updatedAt: "2024-01-15T09:30:00Z",
        };

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

        const response = await client.insight.insightControllerCreate({
            type: "bar",
            queries: [
                {
                    type: "vapiql-json",
                    table: "call",
                    column: "id",
                    operation: "count",
                },
            ],
        });
        expect(response).toEqual({
            type: "bar",
            name: "name",
            formulas: [
                {
                    name: "Booking Rate",
                    formula: "formula",
                },
            ],
            metadata: {
                xAxisLabel: "xAxisLabel",
                yAxisLabel: "yAxisLabel",
                yAxisMin: 1.1,
                yAxisMax: 1.1,
                name: "name",
            },
            timeRange: {
                step: "minute",
                start: {
                    key: "value",
                },
                end: {
                    key: "value",
                },
                timezone: "timezone",
            },
            groupBy: "assistantId",
            queries: [
                {
                    type: "vapiql-json",
                    table: "call",
                    filters: [
                        {
                            column: "assistantId",
                            operator: "=",
                            value: "value",
                        },
                    ],
                    column: "id",
                    operation: "count",
                    name: "Total Calls",
                },
            ],
            id: "id",
            orgId: "orgId",
            createdAt: "2024-01-15T09:30:00Z",
            updatedAt: "2024-01-15T09:30:00Z",
        });
    });

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

        const rawResponseBody = {
            type: "bar",
            name: "name",
            formulas: [{ name: "Booking Rate", formula: "formula" }],
            metadata: {
                xAxisLabel: "xAxisLabel",
                yAxisLabel: "yAxisLabel",
                yAxisMin: 1.1,
                yAxisMax: 1.1,
                name: "name",
            },
            timeRange: { step: "minute", start: { key: "value" }, end: { key: "value" }, timezone: "timezone" },
            groupBy: "assistantId",
            queries: [
                {
                    type: "vapiql-json",
                    table: "call",
                    filters: [{ column: "assistantId", operator: "=", value: "value" }],
                    column: "id",
                    operation: "count",
                    name: "Total Calls",
                },
            ],
            id: "id",
            orgId: "orgId",
            createdAt: "2024-01-15T09:30:00Z",
            updatedAt: "2024-01-15T09:30:00Z",
        };

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

        const response = await client.insight.insightControllerFindOne({
            id: "id",
        });
        expect(response).toEqual({
            type: "bar",
            name: "name",
            formulas: [
                {
                    name: "Booking Rate",
                    formula: "formula",
                },
            ],
            metadata: {
                xAxisLabel: "xAxisLabel",
                yAxisLabel: "yAxisLabel",
                yAxisMin: 1.1,
                yAxisMax: 1.1,
                name: "name",
            },
            timeRange: {
                step: "minute",
                start: {
                    key: "value",
                },
                end: {
                    key: "value",
                },
                timezone: "timezone",
            },
            groupBy: "assistantId",
            queries: [
                {
                    type: "vapiql-json",
                    table: "call",
                    filters: [
                        {
                            column: "assistantId",
                            operator: "=",
                            value: "value",
                        },
                    ],
                    column: "id",
                    operation: "count",
                    name: "Total Calls",
                },
            ],
            id: "id",
            orgId: "orgId",
            createdAt: "2024-01-15T09:30:00Z",
            updatedAt: "2024-01-15T09:30:00Z",
        });
    });

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

        const rawResponseBody = {
            type: "bar",
            name: "name",
            formulas: [{ name: "Booking Rate", formula: "formula" }],
            metadata: {
                xAxisLabel: "xAxisLabel",
                yAxisLabel: "yAxisLabel",
                yAxisMin: 1.1,
                yAxisMax: 1.1,
                name: "name",
            },
            timeRange: { step: "minute", start: { key: "value" }, end: { key: "value" }, timezone: "timezone" },
            groupBy: "assistantId",
            queries: [
                {
                    type: "vapiql-json",
                    table: "call",
                    filters: [{ column: "assistantId", operator: "=", value: "value" }],
                    column: "id",
                    operation: "count",
                    name: "Total Calls",
                },
            ],
            id: "id",
            orgId: "orgId",
            createdAt: "2024-01-15T09:30:00Z",
            updatedAt: "2024-01-15T09:30:00Z",
        };

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

        const response = await client.insight.insightControllerRemove({
            id: "id",
        });
        expect(response).toEqual({
            type: "bar",
            name: "name",
            formulas: [
                {
                    name: "Booking Rate",
                    formula: "formula",
                },
            ],
            metadata: {
                xAxisLabel: "xAxisLabel",
                yAxisLabel: "yAxisLabel",
                yAxisMin: 1.1,
                yAxisMax: 1.1,
                name: "name",
            },
            timeRange: {
                step: "minute",
                start: {
                    key: "value",
                },
                end: {
                    key: "value",
                },
                timezone: "timezone",
            },
            groupBy: "assistantId",
            queries: [
                {
                    type: "vapiql-json",
                    table: "call",
                    filters: [
                        {
                            column: "assistantId",
                            operator: "=",
                            value: "value",
                        },
                    ],
                    column: "id",
                    operation: "count",
                    name: "Total Calls",
                },
            ],
            id: "id",
            orgId: "orgId",
            createdAt: "2024-01-15T09:30:00Z",
            updatedAt: "2024-01-15T09:30:00Z",
        });
    });

    test("InsightController_update", async () => {
        const server = mockServerPool.createServer();
        const client = new VapiClient({ maxRetries: 0, token: "test", environment: server.baseUrl });
        const rawRequestBody = { type: "bar" };
        const rawResponseBody = {
            type: "bar",
            name: "name",
            formulas: [{ name: "Booking Rate", formula: "formula" }],
            metadata: {
                xAxisLabel: "xAxisLabel",
                yAxisLabel: "yAxisLabel",
                yAxisMin: 1.1,
                yAxisMax: 1.1,
                name: "name",
            },
            timeRange: { step: "minute", start: { key: "value" }, end: { key: "value" }, timezone: "timezone" },
            groupBy: "assistantId",
            queries: [
                {
                    type: "vapiql-json",
                    table: "call",
                    filters: [{ column: "assistantId", operator: "=", value: "value" }],
                    column: "id",
                    operation: "count",
                    name: "Total Calls",
                },
            ],
            id: "id",
            orgId: "orgId",
            createdAt: "2024-01-15T09:30:00Z",
            updatedAt: "2024-01-15T09:30:00Z",
        };

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

        const response = await client.insight.insightControllerUpdate({
            id: "id",
            body: {
                type: "bar",
            },
        });
        expect(response).toEqual({
            type: "bar",
            name: "name",
            formulas: [
                {
                    name: "Booking Rate",
                    formula: "formula",
                },
            ],
            metadata: {
                xAxisLabel: "xAxisLabel",
                yAxisLabel: "yAxisLabel",
                yAxisMin: 1.1,
                yAxisMax: 1.1,
                name: "name",
            },
            timeRange: {
                step: "minute",
                start: {
                    key: "value",
                },
                end: {
                    key: "value",
                },
                timezone: "timezone",
            },
            groupBy: "assistantId",
            queries: [
                {
                    type: "vapiql-json",
                    table: "call",
                    filters: [
                        {
                            column: "assistantId",
                            operator: "=",
                            value: "value",
                        },
                    ],
                    column: "id",
                    operation: "count",
                    name: "Total Calls",
                },
            ],
            id: "id",
            orgId: "orgId",
            createdAt: "2024-01-15T09:30:00Z",
            updatedAt: "2024-01-15T09:30:00Z",
        });
    });

    test("InsightController_run", async () => {
        const server = mockServerPool.createServer();
        const client = new VapiClient({ maxRetries: 0, token: "test", environment: server.baseUrl });
        const rawRequestBody = {};
        const rawResponseBody = {
            id: "id",
            insightId: "insightId",
            orgId: "orgId",
            createdAt: "2024-01-15T09:30:00Z",
            updatedAt: "2024-01-15T09:30:00Z",
        };

        server
            .mockEndpoint()
            .post("/reporting/insight/id/run")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.insight.insightControllerRun({
            id: "id",
        });
        expect(response).toEqual({
            id: "id",
            insightId: "insightId",
            orgId: "orgId",
            createdAt: "2024-01-15T09:30:00Z",
            updatedAt: "2024-01-15T09:30:00Z",
        });
    });

    test("InsightController_preview", async () => {
        const server = mockServerPool.createServer();
        const client = new VapiClient({ maxRetries: 0, token: "test", environment: server.baseUrl });
        const rawRequestBody = {
            type: "bar",
            queries: [{ type: "vapiql-json", table: "call", column: "id", operation: "count" }],
        };
        const rawResponseBody = {
            id: "id",
            insightId: "insightId",
            orgId: "orgId",
            createdAt: "2024-01-15T09:30:00Z",
            updatedAt: "2024-01-15T09:30:00Z",
        };

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

        const response = await client.insight.insightControllerPreview({
            type: "bar",
            queries: [
                {
                    type: "vapiql-json",
                    table: "call",
                    column: "id",
                    operation: "count",
                },
            ],
        });
        expect(response).toEqual({
            id: "id",
            insightId: "insightId",
            orgId: "orgId",
            createdAt: "2024-01-15T09:30:00Z",
            updatedAt: "2024-01-15T09:30:00Z",
        });
    });
});
