const ENTITY_SCHEMA_ENTITY_ID = "ai_assistant:entity_schema";
const GLOBAL_TENANT_ID = "00000000-0000-0000-0000-000000000000";
const ENTITY_SCHEMA_SEARCH_CONFIG = {
  /** Maximum entities to return from search */
  defaultLimit: 10,
  /** Minimum relevance score (0-1) */
  minScore: 0.15,
  /** Strategies to use (in priority order) */
  strategies: ["fulltext", "vector"]
};
const entitySchemaEntityConfig = {
  entityId: ENTITY_SCHEMA_ENTITY_ID,
  enabled: true,
  priority: 95,
  // High priority, above API endpoints
  /**
   * Build searchable content from an entity schema.
   */
  buildSource: (ctx) => {
    const entity = ctx.record;
    const className = entity.className || "";
    const tableName = entity.tableName || "";
    const module = entity.module || "";
    const fields = entity.fields || [];
    const relationships = entity.relationships || [];
    const textParts = [
      className,
      tableName.replace(/_/g, " "),
      module,
      // Include field names for searchability
      ...fields.map((f) => f.name),
      // Include relationship targets for searchability
      ...relationships.map((r) => r.target)
    ];
    return {
      text: textParts.filter(Boolean).join(" | "),
      fields: {
        className,
        tableName,
        module,
        fieldCount: fields.length,
        relationshipCount: relationships.length,
        // Store full schema as JSON for retrieval
        schema: JSON.stringify({
          fields,
          relationships
        })
      },
      presenter: {
        title: className,
        subtitle: `${module} \u2022 ${fields.length} fields`,
        icon: "lucide:database"
      },
      checksumSource: { className, tableName, fieldCount: fields.length }
    };
  },
  /**
   * Format result for display in search UI.
   */
  formatResult: (ctx) => {
    const entity = ctx.record;
    return {
      title: entity.className,
      subtitle: `${entity.module} \u2022 ${entity.fields?.length ?? 0} fields`,
      icon: "lucide:database"
    };
  },
  /**
   * Field policy for search strategies.
   */
  fieldPolicy: {
    searchable: ["className", "tableName", "module"],
    hashOnly: [],
    excluded: ["schema"]
    // Don't index the full JSON schema
  }
};
function buildSearchText(entity) {
  const parts = [
    entity.className,
    entity.tableName.replace(/_/g, " "),
    entity.module,
    // Include all field names
    ...entity.fields.map((f) => f.name),
    // Include relationship targets
    ...entity.relationships.map((r) => `${r.relationship} ${r.target}`)
  ];
  return parts.filter(Boolean).join(" | ");
}
function entityToIndexableRecord(entity) {
  const presenter = {
    title: entity.className,
    subtitle: `${entity.module} \u2022 ${entity.fields.length} fields`,
    icon: "lucide:database"
  };
  return {
    entityId: ENTITY_SCHEMA_ENTITY_ID,
    recordId: entity.className,
    tenantId: GLOBAL_TENANT_ID,
    organizationId: null,
    fields: {
      className: entity.className,
      tableName: entity.tableName,
      module: entity.module,
      fieldCount: entity.fields.length,
      relationshipCount: entity.relationships.length,
      // Store full schema as JSON for retrieval
      schema: JSON.stringify({
        fields: entity.fields,
        relationships: entity.relationships
      })
    },
    presenter,
    text: buildSearchText(entity),
    checksumSource: {
      className: entity.className,
      tableName: entity.tableName,
      fieldCount: entity.fields.length
    }
  };
}
function computeEntitiesChecksum(entities) {
  const content = entities.map((e) => `${e.className}:${e.tableName}:${e.fieldCount}`).sort().join("|");
  let hash = 0;
  for (let i = 0; i < content.length; i++) {
    const char = content.charCodeAt(i);
    hash = (hash << 5) - hash + char | 0;
  }
  return hash.toString(16);
}
export {
  ENTITY_SCHEMA_ENTITY_ID,
  ENTITY_SCHEMA_SEARCH_CONFIG,
  GLOBAL_TENANT_ID,
  computeEntitiesChecksum,
  entitySchemaEntityConfig,
  entityToIndexableRecord
};
//# sourceMappingURL=entity-index-config.js.map
