"use strict";
/**
 * Shared JSON-Schema-aligned types for Harper's class-level metadata surfaces.
 *
 * `JsonSchemaFragment` is the public shape authors write to via `static properties`
 * on Resource/Table classes. It mirrors the JSON Schema vocabulary so the same
 * data can drive MCP tool descriptors, OpenAPI components, and any future schema
 * consumer without an intermediate translation layer.
 *
 * `DATA_TYPES` maps Harper's GraphQL primitive type names to JSON Schema type
 * strings. Used by the OpenAPI generator and the GraphQL parser to keep their
 * type emission in lockstep.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.DATA_TYPES = void 0;
exports.attributeToFragment = attributeToFragment;
exports.projectAttributesToProperties = projectAttributesToProperties;
exports.DATA_TYPES = {
    Int: 'integer',
    Float: 'number',
    Long: 'integer',
    ID: 'string',
    String: 'string',
    Boolean: 'boolean',
    Date: 'string',
    Bytes: 'string',
    BigInt: 'integer',
};
/**
 * Project a single attribute to its JSON Schema fragment. Recursive on the
 * `elements` field for array types so an attribute like `tags: [String]`
 * produces `{ type: 'array', items: { type: 'string' } }` instead of the
 * type-only `{ type: 'array' }` that would leave the element shape unknown
 * to MCP / OpenAPI consumers.
 */
function attributeToFragment(attr) {
    const fragment = {};
    // GraphQL parser emits list types as `prop.type === 'array'` with `.elements`
    // describing the inner type. Map that to JSON Schema's items shape; otherwise
    // fall through to the primitive mapping.
    if (attr.type === 'array' && attr.elements) {
        fragment.type = 'array';
        fragment.items = attributeToFragment(attr.elements);
    }
    else {
        const jsonType = attr.type ? exports.DATA_TYPES[attr.type] : undefined;
        if (jsonType)
            fragment.type = jsonType;
        else if (attr.type)
            fragment.type = attr.type;
    }
    if (attr.description)
        fragment.description = attr.description;
    if (attr.isPrimaryKey)
        fragment.primaryKey = true;
    if (attr.assignCreatedTime)
        fragment.assignCreatedTime = true;
    if (attr.assignUpdatedTime)
        fragment.assignUpdatedTime = true;
    if (attr.hidden)
        fragment.hidden = true;
    if (attr.nullable)
        fragment.nullable = true;
    return fragment;
}
/**
 * Project an `Attribute[]` array into a `Record<string, JsonSchemaFragment>`
 * keyed by attribute name. Default canonical-properties source when an author
 * hasn't declared `static properties` on the class.
 */
function projectAttributesToProperties(attributes) {
    const result = {};
    for (const attr of attributes) {
        result[attr.name] = attributeToFragment(attr);
    }
    return result;
}
//# sourceMappingURL=jsonSchemaTypes.js.map