// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import { fromSdkHttpOperationResponse } from "./operation-converter.js";
import { fromSdkType } from "./type-converter.js";
export function fromSdkHttpExamples(sdkContext, examples) {
    return examples.map((example) => fromSdkHttpExample(example));
    function fromSdkHttpExample(example) {
        return {
            kind: "http",
            name: example.name,
            description: example.doc,
            filePath: example.filePath,
            parameters: example.parameters.map((p) => fromSdkParameterExample(p)),
            responses: example.responses.map((r) => fromSdkOperationResponse(r)),
        };
    }
    function fromSdkParameterExample(parameter) {
        return {
            parameter: sdkContext.__typeCache.properties.get(parameter.parameter),
            value: fromSdkExample(parameter.value),
        };
    }
    function fromSdkOperationResponse(responseValue) {
        return {
            response: fromSdkHttpOperationResponse(sdkContext, responseValue.response),
            statusCode: responseValue.statusCode,
            bodyValue: responseValue.bodyValue ? fromSdkExample(responseValue.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(sdkContext, example.type),
            value: example.value,
        };
    }
    function fromSdkNumberExample(example) {
        return {
            kind: "number",
            type: fromSdkType(sdkContext, example.type),
            value: example.value,
        };
    }
    function fromSdkBooleanExample(example) {
        return {
            kind: example.kind,
            type: fromSdkType(sdkContext, example.type),
            value: example.value,
        };
    }
    function fromSdkUnionExample(example) {
        return {
            kind: example.kind,
            type: fromSdkType(sdkContext, example.type),
            value: example.value,
        };
    }
    function fromSdkArrayExample(example) {
        return {
            kind: example.kind,
            type: fromSdkType(sdkContext, example.type),
            value: example.value.map((v) => fromSdkExample(v)),
        };
    }
    function fromSdkDictionaryExample(example) {
        return {
            kind: example.kind,
            type: fromSdkType(sdkContext, example.type),
            value: fromExampleRecord(example.value),
        };
    }
    function fromSdkModelExample(example) {
        return {
            kind: example.kind,
            type: fromSdkType(sdkContext, example.type),
            value: fromExampleRecord(example.value),
            additionalPropertiesValue: example.additionalPropertiesValue
                ? fromExampleRecord(example.additionalPropertiesValue)
                : undefined,
        };
    }
    function fromSdkAnyExample(example) {
        return {
            kind: example.kind,
            type: fromSdkType(sdkContext, example.type),
            value: example.value,
        };
    }
    function fromSdkNullExample(example) {
        return {
            kind: example.kind,
            type: fromSdkType(sdkContext, example.type),
            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