export const isFirstPartyBindingsFileV2 = (manifest) => {
    return ("namespace" in manifest &&
        "dotnet" in manifest &&
        typeof manifest.dotnet === "object" &&
        manifest.dotnet !== null &&
        Array.isArray(manifest.dotnet.types));
};
export const getDotnetBindingPayload = (manifest) => {
    if ("namespace" in manifest &&
        "types" in manifest &&
        !("namespaces" in manifest) &&
        !("dotnet" in manifest)) {
        return manifest;
    }
    if (isFirstPartyBindingsFileV2(manifest)) {
        return {
            namespace: manifest.namespace,
            types: manifest.dotnet.types,
            exports: manifest.dotnet.exports,
        };
    }
    return undefined;
};
export const extractRawDotnetBindingsPayload = (value) => {
    if (typeof value !== "object" || value === null)
        return undefined;
    const candidate = value;
    if (typeof candidate.namespace !== "string") {
        return undefined;
    }
    if (Array.isArray(candidate.types)) {
        return {
            namespace: candidate.namespace,
            types: candidate.types,
            exports: candidate.exports &&
                typeof candidate.exports === "object" &&
                !Array.isArray(candidate.exports)
                ? candidate.exports
                : undefined,
        };
    }
    if (candidate.dotnet !== undefined &&
        typeof candidate.dotnet === "object" &&
        candidate.dotnet !== null &&
        Array.isArray(candidate.dotnet.types)) {
        return {
            namespace: candidate.namespace,
            types: candidate.dotnet.types,
            exports: candidate.dotnet.exports &&
                typeof candidate.dotnet.exports === "object" &&
                !Array.isArray(candidate.dotnet.exports)
                ? candidate.dotnet.exports
                : undefined,
        };
    }
    return undefined;
};
export const extractRawDotnetBindingTypes = (value) => {
    const payload = extractRawDotnetBindingsPayload(value);
    if (!payload) {
        return undefined;
    }
    return payload.types.filter((entry) => entry !== null && typeof entry === "object" && !Array.isArray(entry));
};
export const extractRawDotnetAssemblyName = (value) => {
    const [firstType] = extractRawDotnetBindingTypes(value) ?? [];
    return typeof firstType?.assemblyName === "string"
        ? firstType.assemblyName
        : undefined;
};
//# sourceMappingURL=dotnet-binding-payload.js.map