// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import { getAllModels, getClientType, isAzureCoreModel, } from "@azure-tools/typespec-client-generator-core";
import { getEffectiveModelType } from "@typespec/compiler";
import { getHeaderFieldName, getPathParamName, getQueryParamName, isStatusCode, } from "@typespec/http";
import { fromSdkEnumType, fromSdkModelType, fromSdkType } from "./converter.js";
import { Logger } from "./logger.js";
/**
 * If type is an anonymous model, tries to find a named model that has the same
 * set of properties when non-schema properties are excluded.
 */
export function getEffectiveSchemaType(context, type) {
    let target = type;
    if (type.kind === "Model" && !type.name) {
        const effective = getEffectiveModelType(context.program, type, isSchemaPropertyInternal);
        if (effective.name) {
            target = effective;
        }
    }
    return target;
    function isSchemaPropertyInternal(property) {
        return isSchemaProperty(context, property);
    }
}
/**
 * A "schema property" here is a property that is emitted to OpenAPI schema.
 *
 * Headers, parameters, status codes are not schema properties even they are
 * represented as properties in TypeSpec.
 */
function isSchemaProperty(context, property) {
    const program = context.program;
    const headerInfo = getHeaderFieldName(program, property);
    const queryInfo = getQueryParamName(program, property);
    const pathInfo = getPathParamName(program, property);
    const statusCodeInfo = isStatusCode(program, property);
    return !(headerInfo || queryInfo || pathInfo || statusCodeInfo);
}
export function getDefaultValue(type) {
    switch (type.kind) {
        case "String":
            return type.value;
        case "Number":
            return type.value;
        case "Boolean":
            return type.value;
        case "Tuple":
            return type.values.map(getDefaultValue);
        default:
            return undefined;
    }
}
export function getInputType(context, type, typeCache, operation, literalTypeContext) {
    Logger.getInstance().debug(`getInputType for kind: ${type.kind}`);
    const sdkType = getClientType(context, type, operation);
    return fromSdkType(sdkType, context, typeCache, literalTypeContext);
}
export function navigateModels(context, typeCache) {
    for (const type of getAllModels(context)) {
        if (type.name === "" || isAzureCoreModel(type)) {
            continue;
        }
        if (type.kind === "model") {
            fromSdkModelType(type, context, typeCache);
        }
        else {
            fromSdkEnumType(type, context, typeCache);
        }
    }
}
//# sourceMappingURL=model.js.map