/**
 * Data Architecture V2.2 — Unified DataObject Model (UDM)
 *
 * Defines the core types for the structured data fabric:
 * DataObject, SchemaDefinition, SinkDefinition, and related types.
 *
 * @see specs/crewly-data-architecture-v2.md
 */
// ---------------------------------------------------------------------------
// Type Guards
// ---------------------------------------------------------------------------
/**
 * Runtime check that a value is a valid DataObject.
 *
 * Validates the presence and types of all required top-level fields
 * and the nested metadata structure.
 *
 * @param value - The value to check
 * @returns true if value satisfies the DataObject interface
 */
export function isDataObject(value) {
    if (typeof value !== 'object' || value === null)
        return false;
    const obj = value;
    // Top-level required strings
    if (typeof obj.id !== 'string')
        return false;
    if (!isDataObjectType(obj.type))
        return false;
    if (!isDataObjectScope(obj.scope))
        return false;
    if (typeof obj.schema_id !== 'string')
        return false;
    if (!isDataObjectStatus(obj.status))
        return false;
    if (typeof obj.owner_id !== 'string')
        return false;
    if (typeof obj.namespace !== 'string')
        return false;
    if (!isSyncState(obj.sync_state))
        return false;
    // payload
    if (typeof obj.payload !== 'object' || obj.payload === null)
        return false;
    // metadata
    if (typeof obj.metadata !== 'object' || obj.metadata === null)
        return false;
    const meta = obj.metadata;
    if (typeof meta.created_at !== 'string')
        return false;
    if (typeof meta.updated_at !== 'string')
        return false;
    if (!Array.isArray(meta.tags))
        return false;
    return true;
}
/**
 * Runtime check that a value is a valid SchemaDefinition.
 *
 * @param value - The value to check
 * @returns true if value satisfies the SchemaDefinition interface
 */
export function isSchemaDefinition(value) {
    if (typeof value !== 'object' || value === null)
        return false;
    const obj = value;
    if (typeof obj.id !== 'string')
        return false;
    if (typeof obj.name !== 'string')
        return false;
    if (typeof obj.version !== 'string')
        return false;
    if (typeof obj.fields !== 'object' || obj.fields === null)
        return false;
    if (typeof obj.write_policy !== 'object' || obj.write_policy === null)
        return false;
    const wp = obj.write_policy;
    if (typeof wp.allow_unstructured !== 'boolean')
        return false;
    if (!isValidationLevel(wp.validation_level))
        return false;
    return true;
}
/**
 * Runtime check that a value is a valid SinkDefinition.
 *
 * @param value - The value to check
 * @returns true if value satisfies the SinkDefinition interface
 */
export function isSinkDefinition(value) {
    if (typeof value !== 'object' || value === null)
        return false;
    const obj = value;
    if (typeof obj.id !== 'string')
        return false;
    if (typeof obj.name !== 'string')
        return false;
    if (!isSinkType(obj.type))
        return false;
    if (typeof obj.path !== 'string')
        return false;
    if (!isSinkFormat(obj.format))
        return false;
    if (typeof obj.responsible_agent !== 'string')
        return false;
    if (!Array.isArray(obj.notify))
        return false;
    if (typeof obj.description !== 'string')
        return false;
    return true;
}
// ---------------------------------------------------------------------------
// Internal helpers — narrow literal unions
// ---------------------------------------------------------------------------
/** @internal */
function isDataObjectType(v) {
    return v === 'memory' || v === 'knowledge' || v === 'sink_entry';
}
/** @internal */
function isDataObjectScope(v) {
    return v === 'agent' || v === 'project' || v === 'global';
}
/** @internal */
function isDataObjectStatus(v) {
    return v === 'new' || v === 'processed' || v === 'archived';
}
/** @internal */
function isSyncState(v) {
    return v === 'local' || v === 'synced' || v === 'conflict';
}
/** @internal */
function isValidationLevel(v) {
    return v === 'strict' || v === 'loose' || v === 'none';
}
/** @internal */
function isSinkType(v) {
    return v === 'collection' || v === 'log';
}
/** @internal */
function isSinkFormat(v) {
    return v === 'markdown' || v === 'json' || v === 'jsonl';
}
//# sourceMappingURL=data-object.types.js.map