/**
 * Query API Type Definitions
 *
 * This module defines all types, interfaces, and filters for the Stoneforge Query API.
 * The Query API provides the primary programmatic interface to Stoneforge, enabling
 * CRUD operations, queries, dependency management, and system administration.
 */
// ============================================================================
// Type Guards
// ============================================================================
/**
 * Check if a value is a valid SortDirection
 */
export function isSortDirection(value) {
    return value === 'asc' || value === 'desc';
}
/**
 * Check if a value is a valid ConflictStrategy
 */
export function isConflictStrategy(value) {
    return value === 'skip' || value === 'overwrite' || value === 'error';
}
/**
 * Check if a value is a valid ExportFormat
 */
export function isExportFormat(value) {
    return value === 'jsonl';
}
// ============================================================================
// Validation Helpers
// ============================================================================
/**
 * Validate an ElementFilter object
 */
export function isValidElementFilter(value) {
    if (typeof value !== 'object' || value === null) {
        return false;
    }
    const obj = value;
    // Check limit is positive number if present
    if (obj.limit !== undefined) {
        if (typeof obj.limit !== 'number' || obj.limit < 0 || !Number.isInteger(obj.limit)) {
            return false;
        }
    }
    // Check offset is non-negative number if present
    if (obj.offset !== undefined) {
        if (typeof obj.offset !== 'number' || obj.offset < 0 || !Number.isInteger(obj.offset)) {
            return false;
        }
    }
    // Check orderDir is valid if present
    if (obj.orderDir !== undefined && !isSortDirection(obj.orderDir)) {
        return false;
    }
    // Check tags is array of strings if present
    if (obj.tags !== undefined) {
        if (!Array.isArray(obj.tags) || !obj.tags.every(t => typeof t === 'string')) {
            return false;
        }
    }
    // Check tagsAny is array of strings if present
    if (obj.tagsAny !== undefined) {
        if (!Array.isArray(obj.tagsAny) || !obj.tagsAny.every(t => typeof t === 'string')) {
            return false;
        }
    }
    // Check includeDeleted is boolean if present
    if (obj.includeDeleted !== undefined && typeof obj.includeDeleted !== 'boolean') {
        return false;
    }
    return true;
}
/**
 * Validate a TaskFilter object
 */
export function isValidTaskFilter(value) {
    if (!isValidElementFilter(value)) {
        return false;
    }
    const obj = value;
    // Check hasDeadline is boolean if present
    if (obj.hasDeadline !== undefined && typeof obj.hasDeadline !== 'boolean') {
        return false;
    }
    // Check includeEphemeral is boolean if present
    if (obj.includeEphemeral !== undefined && typeof obj.includeEphemeral !== 'boolean') {
        return false;
    }
    return true;
}
/**
 * Validate a DocumentFilter object
 */
export function isValidDocumentFilter(value) {
    if (!isValidElementFilter(value)) {
        return false;
    }
    const obj = value;
    // Check version is a positive integer if present
    if (obj.version !== undefined) {
        if (typeof obj.version !== 'number' || obj.version < 1 || !Number.isInteger(obj.version)) {
            return false;
        }
    }
    // Check minVersion is a positive integer if present
    if (obj.minVersion !== undefined) {
        if (typeof obj.minVersion !== 'number' || obj.minVersion < 1 || !Number.isInteger(obj.minVersion)) {
            return false;
        }
    }
    // Check maxVersion is a positive integer if present
    if (obj.maxVersion !== undefined) {
        if (typeof obj.maxVersion !== 'number' || obj.maxVersion < 1 || !Number.isInteger(obj.maxVersion)) {
            return false;
        }
    }
    return true;
}
/**
 * Validate a GetOptions object
 */
export function isValidGetOptions(value) {
    if (typeof value !== 'object' || value === null) {
        return false;
    }
    const obj = value;
    if (obj.hydrate !== undefined) {
        if (typeof obj.hydrate !== 'object' || obj.hydrate === null) {
            return false;
        }
        const hydrate = obj.hydrate;
        // All hydration options should be boolean if present
        for (const key of ['description', 'content', 'attachments']) {
            if (hydrate[key] !== undefined && typeof hydrate[key] !== 'boolean') {
                return false;
            }
        }
    }
    return true;
}
/**
 * Validate ExportOptions
 */
export function isValidExportOptions(value) {
    if (typeof value !== 'object' || value === null) {
        return false;
    }
    const obj = value;
    if (obj.format !== undefined && !isExportFormat(obj.format)) {
        return false;
    }
    if (obj.includeDeleted !== undefined && typeof obj.includeDeleted !== 'boolean') {
        return false;
    }
    if (obj.includeDependencies !== undefined && typeof obj.includeDependencies !== 'boolean') {
        return false;
    }
    if (obj.includeEvents !== undefined && typeof obj.includeEvents !== 'boolean') {
        return false;
    }
    return true;
}
/**
 * Validate ImportOptions
 */
export function isValidImportOptions(value) {
    if (typeof value !== 'object' || value === null) {
        return false;
    }
    const obj = value;
    // Must have either inputPath or data
    if (obj.inputPath === undefined && obj.data === undefined) {
        return false;
    }
    if (obj.inputPath !== undefined && typeof obj.inputPath !== 'string') {
        return false;
    }
    if (obj.data !== undefined && typeof obj.data !== 'string') {
        return false;
    }
    if (obj.conflictStrategy !== undefined && !isConflictStrategy(obj.conflictStrategy)) {
        return false;
    }
    if (obj.validateFirst !== undefined && typeof obj.validateFirst !== 'boolean') {
        return false;
    }
    if (obj.dryRun !== undefined && typeof obj.dryRun !== 'boolean') {
        return false;
    }
    return true;
}
// ============================================================================
// Default Values
// ============================================================================
/** Default page size for list queries */
export const DEFAULT_PAGE_SIZE = 10000;
/** Maximum page size for list queries */
export const MAX_PAGE_SIZE = 10000;
/** Default conflict strategy for imports */
export const DEFAULT_CONFLICT_STRATEGY = 'error';
/** Default export format */
export const DEFAULT_EXPORT_FORMAT = 'jsonl';
//# sourceMappingURL=types.js.map