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

import * as Cohere from "../../src/api/index";
import { CohereClient } from "../../src/Client";
import { mockServerPool } from "../mock-server/MockServerPool";

describe("Batches", () => {
    test("list (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = {
            batches: [
                {
                    id: "9439e0e3-49a4-4336-93e3-485fc420bc18",
                    name: "my-batch",
                    creator_id: "b5e1ffb9-49a1-4653-9927-94083316309d",
                    org_id: "62603116-1750-4c04-b1b6-9d5046764bc4",
                    status: "BATCH_STATUS_IN_PROGRESS",
                    created_at: "2024-01-15T09:30:00Z",
                    updated_at: "2024-01-15T09:30:00Z",
                    input_dataset_id: "my-requests-dataset",
                    output_dataset_id: "output_dataset_id",
                    input_tokens: "input_tokens",
                    output_tokens: "output_tokens",
                    model: "command",
                    num_records: 5000,
                    num_successful_records: 1,
                    num_failed_records: 1,
                    status_reason: "status_reason",
                },
            ],
            next_page_token: "next_page_token",
        };
        server.mockEndpoint().get("/v2/batches").respondWith().statusCode(200).jsonBody(rawResponseBody).build();

        const response = await client.batches.list({
            pageSize: 1,
            pageToken: "page_token",
            orderBy: "order_by",
        });
        expect(response).toEqual({
            batches: [
                {
                    id: "9439e0e3-49a4-4336-93e3-485fc420bc18",
                    name: "my-batch",
                    creatorId: "b5e1ffb9-49a1-4653-9927-94083316309d",
                    orgId: "62603116-1750-4c04-b1b6-9d5046764bc4",
                    status: "BATCH_STATUS_IN_PROGRESS",
                    createdAt: new Date("2024-01-15T09:30:00.000Z"),
                    updatedAt: new Date("2024-01-15T09:30:00.000Z"),
                    inputDatasetId: "my-requests-dataset",
                    outputDatasetId: "output_dataset_id",
                    inputTokens: "input_tokens",
                    outputTokens: "output_tokens",
                    model: "command",
                    numRecords: 5000,
                    numSuccessfulRecords: 1,
                    numFailedRecords: 1,
                    statusReason: "status_reason",
                },
            ],
            nextPageToken: "next_page_token",
        });
    });

    test("list (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v2/batches").respondWith().statusCode(400).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.batches.list();
        }).rejects.toThrow(Cohere.BadRequestError);
    });

    test("list (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v2/batches").respondWith().statusCode(401).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.batches.list();
        }).rejects.toThrow(Cohere.UnauthorizedError);
    });

    test("list (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v2/batches").respondWith().statusCode(403).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.batches.list();
        }).rejects.toThrow(Cohere.ForbiddenError);
    });

    test("list (5)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

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

        await expect(async () => {
            return await client.batches.list();
        }).rejects.toThrow(Cohere.NotFoundError);
    });

    test("list (6)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v2/batches").respondWith().statusCode(500).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.batches.list();
        }).rejects.toThrow(Cohere.InternalServerError);
    });

    test("list (7)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v2/batches").respondWith().statusCode(503).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.batches.list();
        }).rejects.toThrow(Cohere.ServiceUnavailableError);
    });

    test("create (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = { name: "name", input_dataset_id: "input_dataset_id", model: "model" };
        const rawResponseBody = {
            batch: {
                id: "id",
                name: "name",
                creator_id: "creator_id",
                org_id: "org_id",
                status: "BATCH_STATUS_UNSPECIFIED",
                created_at: "2024-01-15T09:30:00Z",
                updated_at: "2024-01-15T09:30:00Z",
                input_dataset_id: "input_dataset_id",
                output_dataset_id: "output_dataset_id",
                input_tokens: "input_tokens",
                output_tokens: "output_tokens",
                model: "model",
                num_records: 1,
                num_successful_records: 1,
                num_failed_records: 1,
                status_reason: "status_reason",
            },
        };
        server
            .mockEndpoint()
            .post("/v2/batches")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.batches.create({
            name: "name",
            inputDatasetId: "input_dataset_id",
            model: "model",
        });
        expect(response).toEqual({
            batch: {
                id: "id",
                name: "name",
                creatorId: "creator_id",
                orgId: "org_id",
                status: "BATCH_STATUS_UNSPECIFIED",
                createdAt: new Date("2024-01-15T09:30:00.000Z"),
                updatedAt: new Date("2024-01-15T09:30:00.000Z"),
                inputDatasetId: "input_dataset_id",
                outputDatasetId: "output_dataset_id",
                inputTokens: "input_tokens",
                outputTokens: "output_tokens",
                model: "model",
                numRecords: 1,
                numSuccessfulRecords: 1,
                numFailedRecords: 1,
                statusReason: "status_reason",
            },
        });
    });

    test("create (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = { name: "name", input_dataset_id: "input_dataset_id", model: "model" };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v2/batches")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(400)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.batches.create({
                name: "name",
                inputDatasetId: "input_dataset_id",
                model: "model",
            });
        }).rejects.toThrow(Cohere.BadRequestError);
    });

    test("create (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = { name: "name", input_dataset_id: "input_dataset_id", model: "model" };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v2/batches")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.batches.create({
                name: "name",
                inputDatasetId: "input_dataset_id",
                model: "model",
            });
        }).rejects.toThrow(Cohere.UnauthorizedError);
    });

    test("create (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = { name: "name", input_dataset_id: "input_dataset_id", model: "model" };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v2/batches")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(403)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.batches.create({
                name: "name",
                inputDatasetId: "input_dataset_id",
                model: "model",
            });
        }).rejects.toThrow(Cohere.ForbiddenError);
    });

    test("create (5)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = { name: "name", input_dataset_id: "input_dataset_id", model: "model" };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v2/batches")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.batches.create({
                name: "name",
                inputDatasetId: "input_dataset_id",
                model: "model",
            });
        }).rejects.toThrow(Cohere.NotFoundError);
    });

    test("create (6)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = { name: "name", input_dataset_id: "input_dataset_id", model: "model" };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v2/batches")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(500)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.batches.create({
                name: "name",
                inputDatasetId: "input_dataset_id",
                model: "model",
            });
        }).rejects.toThrow(Cohere.InternalServerError);
    });

    test("create (7)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });
        const rawRequestBody = { name: "name", input_dataset_id: "input_dataset_id", model: "model" };
        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v2/batches")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(503)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.batches.create({
                name: "name",
                inputDatasetId: "input_dataset_id",
                model: "model",
            });
        }).rejects.toThrow(Cohere.ServiceUnavailableError);
    });

    test("retrieve (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = {
            batch: {
                id: "9439e0e3-49a4-4336-93e3-485fc420bc18",
                name: "my-batch",
                creator_id: "b5e1ffb9-49a1-4653-9927-94083316309d",
                org_id: "62603116-1750-4c04-b1b6-9d5046764bc4",
                status: "BATCH_STATUS_IN_PROGRESS",
                created_at: "2025-03-05T14:59:25Z",
                updated_at: "2025-03-05T15:00:26Z",
                input_dataset_id: "my-requests-dataset",
                output_dataset_id: "my-batch-output-c2waz1",
                input_tokens: "0",
                output_tokens: "0",
                model: "batch-command",
                num_records: 5000,
                num_successful_records: 8,
                num_failed_records: 0,
                status_reason: "status_reason",
            },
        };
        server.mockEndpoint().get("/v2/batches/id").respondWith().statusCode(200).jsonBody(rawResponseBody).build();

        const response = await client.batches.retrieve("id");
        expect(response).toEqual({
            batch: {
                id: "9439e0e3-49a4-4336-93e3-485fc420bc18",
                name: "my-batch",
                creatorId: "b5e1ffb9-49a1-4653-9927-94083316309d",
                orgId: "62603116-1750-4c04-b1b6-9d5046764bc4",
                status: "BATCH_STATUS_IN_PROGRESS",
                createdAt: new Date("2025-03-05T14:59:25.000Z"),
                updatedAt: new Date("2025-03-05T15:00:26.000Z"),
                inputDatasetId: "my-requests-dataset",
                outputDatasetId: "my-batch-output-c2waz1",
                inputTokens: "0",
                outputTokens: "0",
                model: "batch-command",
                numRecords: 5000,
                numSuccessfulRecords: 8,
                numFailedRecords: 0,
                statusReason: "status_reason",
            },
        });
    });

    test("retrieve (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v2/batches/id").respondWith().statusCode(400).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.batches.retrieve("id");
        }).rejects.toThrow(Cohere.BadRequestError);
    });

    test("retrieve (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v2/batches/id").respondWith().statusCode(401).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.batches.retrieve("id");
        }).rejects.toThrow(Cohere.UnauthorizedError);
    });

    test("retrieve (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v2/batches/id").respondWith().statusCode(403).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.batches.retrieve("id");
        }).rejects.toThrow(Cohere.ForbiddenError);
    });

    test("retrieve (5)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

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

        await expect(async () => {
            return await client.batches.retrieve("id");
        }).rejects.toThrow(Cohere.NotFoundError);
    });

    test("retrieve (6)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v2/batches/id").respondWith().statusCode(500).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.batches.retrieve("id");
        }).rejects.toThrow(Cohere.InternalServerError);
    });

    test("retrieve (7)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v2/batches/id").respondWith().statusCode(503).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.batches.retrieve("id");
        }).rejects.toThrow(Cohere.ServiceUnavailableError);
    });

    test("cancel (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v2/batches/id:cancel")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.batches.cancel("id");
        expect(response).toEqual({
            key: "value",
        });
    });

    test("cancel (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v2/batches/id:cancel")
            .respondWith()
            .statusCode(400)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.batches.cancel("id");
        }).rejects.toThrow(Cohere.BadRequestError);
    });

    test("cancel (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v2/batches/id:cancel")
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.batches.cancel("id");
        }).rejects.toThrow(Cohere.UnauthorizedError);
    });

    test("cancel (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v2/batches/id:cancel")
            .respondWith()
            .statusCode(403)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.batches.cancel("id");
        }).rejects.toThrow(Cohere.ForbiddenError);
    });

    test("cancel (5)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v2/batches/id:cancel")
            .respondWith()
            .statusCode(404)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.batches.cancel("id");
        }).rejects.toThrow(Cohere.NotFoundError);
    });

    test("cancel (6)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v2/batches/id:cancel")
            .respondWith()
            .statusCode(500)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.batches.cancel("id");
        }).rejects.toThrow(Cohere.InternalServerError);
    });

    test("cancel (7)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/v2/batches/id:cancel")
            .respondWith()
            .statusCode(503)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.batches.cancel("id");
        }).rejects.toThrow(Cohere.ServiceUnavailableError);
    });
});
