import { 
// eslint-disable-next-line @typescript-eslint/no-redeclare
hasOwnProperty, mapFromObject, } from "collection-utils";
import { uriInferenceAttributesProducer } from "../attributes/URIAttributes.js";
/**
 * All the transformed string type kinds and the JSON Schema formats and
 * primitive type kinds they map to.  Not all transformed string types map to
 * primitive types.  Date-time types, for example, stand on their own, but
 * stringified integers map to integers.
 */
const transformedStringTypeTargetTypeKinds = {
    date: { jsonSchema: "date", primitive: undefined },
    time: { jsonSchema: "time", primitive: undefined },
    "date-time": { jsonSchema: "date-time", primitive: undefined },
    uuid: { jsonSchema: "uuid", primitive: undefined },
    uri: {
        jsonSchema: "uri",
        primitive: undefined,
        attributesProducer: uriInferenceAttributesProducer,
    },
    "integer-string": {
        jsonSchema: "integer",
        primitive: "integer",
    },
    "bool-string": {
        jsonSchema: "boolean",
        primitive: "bool",
    },
};
export const transformedStringTypeTargetTypeKindsMap = mapFromObject(transformedStringTypeTargetTypeKinds);
export const transformedStringTypeKinds = new Set(Object.getOwnPropertyNames(transformedStringTypeTargetTypeKinds));
export function isPrimitiveStringTypeKind(kind) {
    return (kind === "string" ||
        hasOwnProperty(transformedStringTypeTargetTypeKinds, kind));
}
export function targetTypeKindForTransformedStringTypeKind(kind) {
    const target = transformedStringTypeTargetTypeKindsMap.get(kind);
    if (target === undefined)
        return undefined;
    return target.primitive;
}
export function isNumberTypeKind(kind) {
    return kind === "integer" || kind === "double";
}
export function isPrimitiveTypeKind(kind) {
    if (isPrimitiveStringTypeKind(kind))
        return true;
    if (isNumberTypeKind(kind))
        return true;
    return (kind === "none" || kind === "any" || kind === "null" || kind === "bool");
}
export function triviallyStructurallyCompatible(x, y) {
    if (x.index === y.index)
        return true;
    if (x.kind === "none" || y.kind === "none")
        return true;
    return false;
}
