// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import { fromSdkType } from "./converter.js";
export function fromSdkHttpExamples(sdkContext, examples, parameterMap, responseMap, typeMap) {
    return examples.map((example) => fromSdkHttpExample(example));
    function fromSdkHttpExample(example) {
        return {
            kind: "http",
            name: example.name,
            description: example.description,
            filePath: example.filePath,
            parameters: example.parameters.map((p) => fromSdkParameterExample(p)),
            responses: fromSdkOperationResponses(example.responses),
        };
    }
    function fromSdkParameterExample(parameter) {
        return {
            parameter: parameterMap.get(parameter.parameter),
            value: fromSdkExample(parameter.value),
        };
    }
    function fromSdkOperationResponses(responses) {
        const result = [];
        for (const response of responses) {
            result.push(fromSdkOperationResponse(response));
        }
        return result;
    }
    function fromSdkOperationResponse(response) {
        return {
            response: responseMap.get(response.response),
            statusCode: response.statusCode,
            bodyValue: response.bodyValue ? fromSdkExample(response.bodyValue) : undefined,
        };
    }
    function fromSdkExample(example) {
        switch (example.kind) {
            case "string":
                return fromSdkStringExample(example);
            case "number":
                return fromSdkNumberExample(example);
            case "boolean":
                return fromSdkBooleanExample(example);
            case "union":
                return fromSdkUnionExample(example);
            case "array":
                return fromSdkArrayExample(example);
            case "dict":
                return fromSdkDictionaryExample(example);
            case "model":
                return fromSdkModelExample(example);
            case "unknown":
                return fromSdkAnyExample(example);
            case "null":
                return fromSdkNullExample(example);
        }
    }
    function fromSdkStringExample(example) {
        return {
            kind: "string",
            type: fromSdkType(example.type, sdkContext, typeMap),
            value: example.value,
        };
    }
    function fromSdkNumberExample(example) {
        return {
            kind: "number",
            type: fromSdkType(example.type, sdkContext, typeMap),
            value: example.value,
        };
    }
    function fromSdkBooleanExample(example) {
        return {
            kind: example.kind,
            type: fromSdkType(example.type, sdkContext, typeMap),
            value: example.value,
        };
    }
    function fromSdkUnionExample(example) {
        return {
            kind: example.kind,
            type: fromSdkType(example.type, sdkContext, typeMap),
            value: example.value,
        };
    }
    function fromSdkArrayExample(example) {
        return {
            kind: example.kind,
            type: fromSdkType(example.type, sdkContext, typeMap),
            value: example.value.map((v) => fromSdkExample(v)),
        };
    }
    function fromSdkDictionaryExample(example) {
        return {
            kind: example.kind,
            type: fromSdkType(example.type, sdkContext, typeMap),
            value: fromExampleRecord(example.value),
        };
    }
    function fromSdkModelExample(example) {
        return {
            kind: example.kind,
            type: fromSdkType(example.type, sdkContext, typeMap),
            value: fromExampleRecord(example.value),
            additionalPropertiesValue: example.additionalPropertiesValue
                ? fromExampleRecord(example.additionalPropertiesValue)
                : undefined,
        };
    }
    function fromSdkAnyExample(example) {
        return {
            kind: example.kind,
            type: fromSdkType(example.type, sdkContext, typeMap),
            value: example.value,
        };
    }
    function fromSdkNullExample(example) {
        return {
            kind: example.kind,
            type: fromSdkType(example.type, sdkContext, typeMap),
            value: example.value,
        };
    }
    function fromExampleRecord(value) {
        return Object.entries(value).reduce((acc, [key, value]) => {
            acc[key] = fromSdkExample(value);
            return acc;
        }, {});
    }
}
//# sourceMappingURL=example-converter.js.map