// 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("Models", () => {
    test("get (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new CohereClient({ token: "test", clientName: "test", environment: server.baseUrl });

        const rawResponseBody = {
            name: "name",
            is_deprecated: true,
            endpoints: ["chat"],
            finetuned: true,
            context_length: 1.1,
            tokenizer_url: "tokenizer_url",
            default_endpoints: ["chat"],
            features: ["features"],
        };
        server
            .mockEndpoint()
            .get("/v1/models/command-a-03-2025")
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.models.get("command-a-03-2025");
        expect(response).toEqual({
            name: "name",
            isDeprecated: true,
            endpoints: ["chat"],
            finetuned: true,
            contextLength: 1.1,
            tokenizerUrl: "tokenizer_url",
            defaultEndpoints: ["chat"],
            features: ["features"],
        });
    });

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

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

        await expect(async () => {
            return await client.models.get("model");
        }).rejects.toThrow(Cohere.BadRequestError);
    });

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

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

        await expect(async () => {
            return await client.models.get("model");
        }).rejects.toThrow(Cohere.UnauthorizedError);
    });

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

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

        await expect(async () => {
            return await client.models.get("model");
        }).rejects.toThrow(Cohere.ForbiddenError);
    });

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

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

        await expect(async () => {
            return await client.models.get("model");
        }).rejects.toThrow(Cohere.NotFoundError);
    });

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

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v1/models/model").respondWith().statusCode(422).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.models.get("model");
        }).rejects.toThrow(Cohere.UnprocessableEntityError);
    });

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

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v1/models/model").respondWith().statusCode(429).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.models.get("model");
        }).rejects.toThrow(Cohere.TooManyRequestsError);
    });

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

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v1/models/model").respondWith().statusCode(498).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.models.get("model");
        }).rejects.toThrow(Cohere.InvalidTokenError);
    });

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

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v1/models/model").respondWith().statusCode(499).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.models.get("model");
        }).rejects.toThrow(Cohere.ClientClosedRequestError);
    });

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

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

        await expect(async () => {
            return await client.models.get("model");
        }).rejects.toThrow(Cohere.InternalServerError);
    });

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

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v1/models/model").respondWith().statusCode(501).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.models.get("model");
        }).rejects.toThrow(Cohere.NotImplementedError);
    });

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

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

        await expect(async () => {
            return await client.models.get("model");
        }).rejects.toThrow(Cohere.ServiceUnavailableError);
    });

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

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v1/models/model").respondWith().statusCode(504).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.models.get("model");
        }).rejects.toThrow(Cohere.GatewayTimeoutError);
    });

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

        const rawResponseBody = {
            models: [
                {
                    name: "name",
                    is_deprecated: true,
                    endpoints: ["chat"],
                    finetuned: true,
                    context_length: 1.1,
                    tokenizer_url: "tokenizer_url",
                    default_endpoints: ["chat"],
                    features: ["features"],
                },
            ],
            next_page_token: "next_page_token",
        };
        server.mockEndpoint().get("/v1/models").respondWith().statusCode(200).jsonBody(rawResponseBody).build();

        const response = await client.models.list({
            pageSize: 1.1,
            pageToken: "page_token",
            endpoint: "chat",
            defaultOnly: true,
        });
        expect(response).toEqual({
            models: [
                {
                    name: "name",
                    isDeprecated: true,
                    endpoints: ["chat"],
                    finetuned: true,
                    contextLength: 1.1,
                    tokenizerUrl: "tokenizer_url",
                    defaultEndpoints: ["chat"],
                    features: ["features"],
                },
            ],
            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("/v1/models").respondWith().statusCode(400).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.models.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("/v1/models").respondWith().statusCode(401).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.models.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("/v1/models").respondWith().statusCode(403).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.models.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("/v1/models").respondWith().statusCode(404).jsonBody(rawResponseBody).build();

        await expect(async () => {
            return await client.models.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("/v1/models").respondWith().statusCode(422).jsonBody(rawResponseBody).build();

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

    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("/v1/models").respondWith().statusCode(429).jsonBody(rawResponseBody).build();

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

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

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v1/models").respondWith().statusCode(498).jsonBody(rawResponseBody).build();

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

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

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v1/models").respondWith().statusCode(499).jsonBody(rawResponseBody).build();

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

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

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

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

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

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v1/models").respondWith().statusCode(501).jsonBody(rawResponseBody).build();

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

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

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

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

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

        const rawResponseBody = { key: "value" };
        server.mockEndpoint().get("/v1/models").respondWith().statusCode(504).jsonBody(rawResponseBody).build();

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