/**
 * Analytics Types
 *
 * Type definitions for the SpecWeave usage analytics system.
 * Tracks command invocations, skill activations, and agent spawns.
 */
const VALID_EVENT_TYPES = new Set(['command', 'skill', 'agent']);
/**
 * Parse and validate raw JSON into an AnalyticsEvent.
 * Returns null if required fields are missing or invalid.
 * Defaults success to true for legacy events missing the field.
 */
export function parseAnalyticsEvent(raw) {
    if (typeof raw !== 'object' || raw === null)
        return null;
    const obj = raw;
    if (typeof obj.timestamp !== 'string')
        return null;
    if (typeof obj.name !== 'string')
        return null;
    if (!VALID_EVENT_TYPES.has(obj.type))
        return null;
    return {
        timestamp: obj.timestamp,
        type: obj.type,
        name: obj.name,
        success: typeof obj.success === 'boolean' ? obj.success : true,
        plugin: typeof obj.plugin === 'string' ? obj.plugin : undefined,
        increment: typeof obj.increment === 'string' ? obj.increment : undefined,
        duration: typeof obj.duration === 'number' ? obj.duration : undefined,
        error: typeof obj.error === 'string' ? obj.error : undefined,
        metadata: typeof obj.metadata === 'object' && obj.metadata !== null
            ? obj.metadata : undefined,
    };
}
/**
 * Default analytics configuration
 */
export const DEFAULT_ANALYTICS_CONFIG = {
    maxLogSizeBytes: 10 * 1024 * 1024, // 10MB
    retentionDays: 30,
    enabled: true,
};
//# sourceMappingURL=types.js.map