import { IconBrain } from '@tabler/icons-react';
import { z } from 'zod';

/**
 * Date formatting utilities for consistent date display across the application
 */
/**
 * Format a date string for display with date and time
 *
 * @param dateString - ISO date string or null
 * @returns Formatted date string (e.g., "Dec 9, 2025, 10:30 AM") or "Never" if null
 *
 * @example
 * formatDateTime('2025-12-09T10:30:00Z') // "Dec 9, 2025, 10:30 AM"
 * formatDateTime(null) // "Never"
 */
declare function formatDateTime(dateString: string | null): string;
/**
 * Format a date string for display (date only, no time)
 *
 * @param dateString - ISO date string or null
 * @returns Formatted date string (e.g., "Dec 9, 2025") or "Never" if null
 *
 * @example
 * formatDate('2025-12-09T10:30:00Z') // "Dec 9, 2025"
 * formatDate(null) // "Never"
 */
declare function formatDate(dateString: string | null): string;
/**
 * Format a date string for chart axis labels (compact format)
 *
 * @param dateString - ISO date string or null
 * @returns Compact formatted string (e.g., "12/8, 9PM") or empty string if null
 *
 * @example
 * formatChartAxisDate('2025-12-08T21:00:00.000Z') // "12/8, 9PM"
 * formatChartAxisDate('2025-12-09T13:00:00.000Z') // "12/9, 1PM"
 */
declare function formatChartAxisDate(dateString: string | null): string;

/**
 * Format a date as verbose relative time using date-fns (e.g., "about 2 hours ago")
 */
declare function formatRelativeTime(date: string | Date | null | undefined): string;
/**
 * Format a date as compact relative time without external deps (e.g., "2h ago", "3d ago")
 */
declare function formatTimeAgo(date: string | Date | null | undefined): string;

declare const validateEmail: (email: string) => boolean;

/**
 * Debounce utility for delaying function execution
 *
 * Creates a debounced version of a function that delays invoking until
 * after `wait` milliseconds have elapsed since the last time it was invoked.
 */
/**
 * Creates a debounced function that delays invoking `fn` until after `wait`
 * milliseconds have elapsed since the last time the debounced function was invoked.
 *
 * @param fn - The function to debounce
 * @param wait - The number of milliseconds to delay
 * @returns A debounced version of the function with a `cancel` method
 *
 * @example
 * const debouncedSearch = debounce((query: string) => {
 *   console.log('Searching for:', query)
 * }, 300)
 *
 * debouncedSearch('a')
 * debouncedSearch('ab')
 * debouncedSearch('abc') // Only this one executes after 300ms
 *
 * // Cancel pending execution
 * debouncedSearch.cancel()
 */
declare function debounce<T extends (...args: Parameters<T>) => void>(fn: T, wait: number): ((...args: Parameters<T>) => void) & {
    cancel: () => void;
};

declare const ResourceGovernanceStatusSchema: z.ZodEnum<{
    active: "active";
    deprecated: "deprecated";
    archived: "archived";
}>;
type ResourceGovernanceStatus = z.infer<typeof ResourceGovernanceStatusSchema>;

declare const OntologyScopeSchema: z.ZodDefault<z.ZodObject<{
    objectTypes: z.ZodOptional<z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
        id: z.ZodString;
        label: z.ZodOptional<z.ZodString>;
        description: z.ZodOptional<z.ZodString>;
        ownerSystemId: z.ZodOptional<z.ZodString>;
        aliases: z.ZodOptional<z.ZodArray<z.ZodString>>;
        properties: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
        storage: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
    }, z.core.$loose>>>>;
    linkTypes: z.ZodOptional<z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
        id: z.ZodString;
        label: z.ZodOptional<z.ZodString>;
        description: z.ZodOptional<z.ZodString>;
        ownerSystemId: z.ZodOptional<z.ZodString>;
        aliases: z.ZodOptional<z.ZodArray<z.ZodString>>;
        from: z.ZodString;
        to: z.ZodString;
        cardinality: z.ZodOptional<z.ZodString>;
        via: z.ZodOptional<z.ZodString>;
    }, z.core.$loose>>>>;
    actionTypes: z.ZodOptional<z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
        id: z.ZodString;
        label: z.ZodOptional<z.ZodString>;
        description: z.ZodOptional<z.ZodString>;
        ownerSystemId: z.ZodOptional<z.ZodString>;
        aliases: z.ZodOptional<z.ZodArray<z.ZodString>>;
        actsOn: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodString>>>;
        input: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
        effects: z.ZodOptional<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
    }, z.core.$loose>>>>;
    catalogTypes: z.ZodOptional<z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
        id: z.ZodString;
        label: z.ZodOptional<z.ZodString>;
        description: z.ZodOptional<z.ZodString>;
        ownerSystemId: z.ZodOptional<z.ZodString>;
        aliases: z.ZodOptional<z.ZodArray<z.ZodString>>;
        kind: z.ZodOptional<z.ZodString>;
        appliesTo: z.ZodOptional<z.ZodString>;
        entries: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
    }, z.core.$loose>>>>;
    eventTypes: z.ZodOptional<z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
        id: z.ZodString;
        label: z.ZodOptional<z.ZodString>;
        description: z.ZodOptional<z.ZodString>;
        ownerSystemId: z.ZodOptional<z.ZodString>;
        aliases: z.ZodOptional<z.ZodArray<z.ZodString>>;
        payload: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
    }, z.core.$loose>>>>;
    interfaceTypes: z.ZodOptional<z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
        id: z.ZodString;
        label: z.ZodOptional<z.ZodString>;
        description: z.ZodOptional<z.ZodString>;
        ownerSystemId: z.ZodOptional<z.ZodString>;
        aliases: z.ZodOptional<z.ZodArray<z.ZodString>>;
        properties: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
    }, z.core.$loose>>>>;
    valueTypes: z.ZodOptional<z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
        id: z.ZodString;
        label: z.ZodOptional<z.ZodString>;
        description: z.ZodOptional<z.ZodString>;
        ownerSystemId: z.ZodOptional<z.ZodString>;
        aliases: z.ZodOptional<z.ZodArray<z.ZodString>>;
        primitive: z.ZodOptional<z.ZodString>;
    }, z.core.$loose>>>>;
    sharedProperties: z.ZodOptional<z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
        id: z.ZodString;
        label: z.ZodOptional<z.ZodString>;
        description: z.ZodOptional<z.ZodString>;
        ownerSystemId: z.ZodOptional<z.ZodString>;
        aliases: z.ZodOptional<z.ZodArray<z.ZodString>>;
        valueType: z.ZodOptional<z.ZodString>;
        searchable: z.ZodOptional<z.ZodBoolean>;
        pii: z.ZodOptional<z.ZodBoolean>;
    }, z.core.$loose>>>>;
    groups: z.ZodOptional<z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
        id: z.ZodString;
        label: z.ZodOptional<z.ZodString>;
        description: z.ZodOptional<z.ZodString>;
        ownerSystemId: z.ZodOptional<z.ZodString>;
        aliases: z.ZodOptional<z.ZodArray<z.ZodString>>;
        members: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodString>>>;
    }, z.core.$loose>>>>;
    endpoints: z.ZodOptional<z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
        id: z.ZodString;
        label: z.ZodOptional<z.ZodString>;
        description: z.ZodOptional<z.ZodString>;
        ownerSystemId: z.ZodOptional<z.ZodString>;
        aliases: z.ZodOptional<z.ZodArray<z.ZodString>>;
        route: z.ZodOptional<z.ZodString>;
    }, z.core.$loose>>>>;
}, z.core.$strip>>;
type OntologyScope = z.infer<typeof OntologyScopeSchema>;

declare const SystemApiInterfaceSchema: z.ZodObject<{
    lifecycle: z.ZodDefault<z.ZodEnum<{
        active: "active";
        deprecated: "deprecated";
        draft: "draft";
        archived: "archived";
        disabled: "disabled";
    }>>;
    readinessProfile: z.ZodOptional<z.ZodEnum<{
        "sales.lead-gen.api": "sales.lead-gen.api";
        "sales.crm.api": "sales.crm.api";
        "sales.lead-gen.crm-handoff": "sales.lead-gen.crm-handoff";
    }>>;
    resourceIds: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodString>>>;
}, z.core.$strict>;
type JsonPrimitive = string | number | boolean | null;
type JsonValue = JsonPrimitive | JsonValue[] | {
    [key: string]: JsonValue;
};
/** Explicit interface needed to annotate the recursive SystemEntrySchema. */
interface SystemEntry {
    id: string;
    label?: string;
    title?: string;
    description?: string;
    kind?: 'product' | 'operational' | 'platform' | 'diagnostic';
    parentSystemId?: string;
    ui?: {
        path: string;
        surfaces: string[];
        icon?: string;
        order?: number;
    };
    lifecycle?: 'draft' | 'beta' | 'active' | 'deprecated' | 'archived';
    responsibleRoleId?: string;
    governedByKnowledge?: string[];
    actions?: {
        actionId: string;
        intent: 'exposes' | 'consumes';
        invocation?: unknown;
    }[];
    policies?: string[];
    drivesGoals?: string[];
    apiInterface?: z.infer<typeof SystemApiInterfaceSchema>;
    /** @deprecated Use lifecycle. Accepted for one publish cycle. */
    status?: 'active' | 'deprecated' | 'archived';
    path?: string;
    icon?: string;
    uiPosition?: 'sidebar-primary' | 'sidebar-bottom';
    enabled?: boolean;
    devOnly?: boolean;
    requiresAdmin?: boolean;
    order: number;
    config?: Record<string, JsonValue>;
    ontology?: OntologyScope;
    systems?: Record<string, SystemEntry>;
    subsystems?: Record<string, SystemEntry>;
}

declare const LinkSchema: z.ZodObject<{
    nodeId: z.ZodString;
    kind: z.ZodEnum<{
        affects: "affects";
        actions: "actions";
        effects: "effects";
        links: "links";
        reads: "reads";
        writes: "writes";
        emits: "emits";
        triggers: "triggers";
        uses: "uses";
        approval: "approval";
        contains: "contains";
        references: "references";
        maps_to: "maps_to";
        governs: "governs";
        originates_from: "originates_from";
        applies_to: "applies_to";
        uses_catalog: "uses_catalog";
    }>;
}, z.core.$strip>;
type Link = z.infer<typeof LinkSchema>;

/**
 * Time range selector for dashboard metrics
 */
type TimeRange = '1h' | '24h' | '7d' | '30d';
/**
 * ISO 8601 date range for API queries
 */
interface TimeRangeDates {
    startDate: string;
    endDate: string;
}

/**
 * Base Execution Engine type definitions
 * Core types shared across all Execution Engine resources
 */

declare const ResourceStatusColors: {
    readonly dev: "var(--color-primary)";
    readonly prod: "var(--color-success)";
};

/**
 * Resource Registry type definitions
 */

/**
 * Environment/deployment status for resources
 */
type ResourceStatus = 'dev' | 'prod';
/**
 * All resource types in the platform
 * Used as the discriminator field in ResourceDefinition
 */
type ResourceType = 'agent' | 'workflow' | 'trigger' | 'integration' | 'external' | 'human';
type ResourceSystemSummary = Pick<SystemEntry, 'id' | 'title' | 'description' | 'kind' | 'lifecycle'>;
/**
 * Base interface for ALL platform resources
 * Shared by both executable (agents, workflows) and non-executable (triggers, integrations, etc.) resources
 */
interface ResourceDefinition {
    /** Unique resource identifier */
    resourceId: string;
    /** Display name */
    name: string;
    /** Purpose and functionality description */
    description: string;
    /** Version for change tracking and evolution */
    version: string;
    /** Resource type discriminator */
    type: ResourceType;
    /** Environment/deployment status */
    status: ResourceStatus;
    /** Graph links to Organization Model nodes */
    links?: ResourceLink[];
    /** Infrastructure category for filtering */
    category?: ResourceCategory;
    /** Whether the agent supports multi-turn sessions (agents only) */
    sessionCapable?: boolean;
    /** Whether the resource is local (monorepo) or remote (externally deployed) */
    origin?: 'local' | 'remote';
    /** OM System membership — dot-separated system path (e.g. "sys.lead-gen"), when backed by a Resource descriptor */
    systemPath?: string;
    /** Display metadata for the owning OM System */
    system?: ResourceSystemSummary;
    /** Governance lifecycle status from the OM Resource descriptor */
    governanceStatus?: ResourceGovernanceStatus;
    /** Whether this resource is archived and should be excluded from registration and deployment */
    archived?: boolean;
}

declare const ResourceCategorySchema: z.ZodEnum<{
    diagnostic: "diagnostic";
    production: "production";
    internal: "internal";
    testing: "testing";
}>;
type ResourceCategory = z.infer<typeof ResourceCategorySchema>;
type ResourceLink = Link;

/**
 * Resource Type Metadata
 *
 * Centralized metadata for ResourceDefinition types including icon names and colors.
 * Icon names reference @tabler/icons-react - UI layer maps these to actual components.
 */

/**
 * All valid resource types from ResourceDefinition
 * Derived from the base interface to ensure consistency
 */
type ResourceDefinitionType = ResourceDefinition['type'];
/**
 * Node color types for graph visualization
 * Used by both @repo/core (metadata) and @repo/ui (components)
 */
type NodeColorType = 'violet' | 'blue' | 'orange' | 'teal' | 'gray' | 'yellow';
/**
 * Get color for a resource type
 */
declare function getResourceColor(type: ResourceDefinitionType): NodeColorType;

/**
 * Type-safe error codes
 * MUST match API_ERROR_CODES in apps/api/src/errors/error-codes.ts
 */
type APIErrorCode = 'VALIDATION_ERROR' | 'AUTHENTICATION_FAILED' | 'FORBIDDEN' | 'NOT_FOUND' | 'CONFLICT' | 'RATE_LIMIT_EXCEEDED' | 'INTERNAL_SERVER_ERROR' | 'SERVICE_UNAVAILABLE';

/**
 * Time range utility functions
 * Converts TimeRange enum to ISO 8601 date strings and labels
 */

/**
 * Convert TimeRange to start and end ISO 8601 date strings
 * @param range - Time range enum (1h, 24h, 7d, 30d)
 * @returns Object with startDate and endDate as ISO 8601 strings
 */
declare function getTimeRangeDates(range: TimeRange): TimeRangeDates;
/**
 * Get a human-readable label for a time range
 * @param range - Time range enum
 * @returns Human-readable label
 */
declare function getTimeRangeLabel(range: TimeRange): string;

/**
 * API Client Error class for type-safe error handling
 * Used by API clients to provide structured error information
 */
declare class APIClientError extends Error {
    readonly statusCode: number;
    readonly code: APIErrorCode;
    readonly requestId?: string;
    readonly fields?: Record<string, string[]>;
    readonly retryAfter?: number;
    constructor(message: string, code: APIErrorCode, statusCode: number, requestId?: string, fields?: Record<string, string[]>, retryAfter?: number);
}
/**
 * Type guard to check if an error is an APIClientError
 */
declare function isAPIClientError(error: unknown): error is APIClientError;
/**
 * Extract error information from any error type
 * Handles both APIClientError and generic Error instances
 */
declare function getErrorInfo(error: unknown): {
    message: string;
    code?: APIErrorCode;
    requestId?: string;
    statusCode?: number;
    fields?: Record<string, string[]>;
    retryAfter?: number;
};
/**
 * Get user-friendly error title based on error code
 */
declare function getErrorTitle(code?: APIErrorCode): string;
/**
 * Format error message with field errors and request ID if available
 */
declare function formatErrorMessage(message: string, requestId?: string, fields?: Record<string, string[]>, retryAfter?: number): string;

/**
 * Resource Icon Resolver
 *
 * Maps icon name strings from @repo/core to actual React icon components.
 * This allows @repo/core to define icon metadata without React dependencies.
 */

/**
 * Tabler icon component type
 */
type TablerIcon = typeof IconBrain;
/**
 * Get icon component for a resource type
 */
declare function getResourceIcon(type: ResourceDefinitionType): TablerIcon;

/**
 * Default API URL constant for the Elevasis platform.
 *
 * Reads `import.meta.env.PROD` — resolves to the production API host when
 * Vite builds in production mode, and falls back to the local dev server.
 *
 * Consumer apps that need a different host should override this by reading
 * their own environment variable rather than re-exporting this constant.
 */
declare const API_URL: string;

/** Monitoring and analytics stale time (30s). */
declare const STALE_TIME_MONITORING = 30000;
/** Admin data stale time (1 min). */
declare const STALE_TIME_ADMIN = 60000;
/** Global default and static data stale time (5 min). Matches queryClient default. */
declare const STALE_TIME_DEFAULT = 300000;
/** Short-lived cache garbage collection for admin/resource hooks (5 min). */
declare const GC_TIME_SHORT = 300000;
/** Medium-lived cache garbage collection for resource detail hooks (10 min). */
declare const GC_TIME_MEDIUM = 600000;
/** Long-lived cache garbage collection for resource definitions (30 min). Matches queryClient default. */
declare const GC_TIME_LONG = 1800000;

/** Dashboard and monitoring data polling interval (60s). */
declare const REFETCH_INTERVAL_DASHBOARD = 60000;
/** Near-real-time data polling for logs and activities (30s). */
declare const REFETCH_INTERVAL_REALTIME = 30000;
/** Active execution detail polling when status is 'running' (2s). */
declare const REFETCH_INTERVAL_RUNNING = 2000;
/** Execution runner list polling when executions are active (1s). */
declare const REFETCH_INTERVAL_RUNNING_FAST = 1000;

/** SSE reconnect delay after token refresh (2s). */
declare const SSE_TOKEN_REFRESH_DELAY = 2000;
/** SSE unsubscribe grace period for tab switching (5s). */
declare const SSE_CLOSE_GRACE_PERIOD = 5000;
/** WebSocket exponential backoff base delay (1s). */
declare const WS_RECONNECT_BASE_DELAY = 1000;
/** WebSocket reconnect delay cap (30s). */
declare const WS_RECONNECT_MAX_DELAY = 30000;
/** WebSocket retries before showing error state. */
declare const WS_MAX_RETRIES_BEFORE_ERROR = 3;

/** Standard page size for lists (command queue, notifications). */
declare const PAGE_SIZE_DEFAULT = 20;
/** Activity feed page size and load-more increment. */
declare const LIMIT_ACTIVITY_FEED = 50;
/** Search/filter input debounce delay (150ms). */
declare const DEBOUNCE_FILTER = 150;
/** Slider input debounce delay (500ms). */
declare const DEBOUNCE_SLIDER = 500;
/** OAuth flow maximum duration before timeout (5 min). */
declare const OAUTH_FLOW_TIMEOUT = 300000;

/**
 * Suppresses known non-critical console warnings in development
 *
 * This utility filters out warnings that are:
 * - Coming from third-party libraries (e.g., Mantine deprecation warnings)
 * - Non-breaking and do not affect functionality
 * - Expected to be fixed in future library updates
 */
/**
 * Initializes warning suppression by intercepting console.error and console.warn
 * Call this once at application startup
 */
declare function suppressKnownWarnings(): void;
/**
 * Restores original console.error and console.warn behavior
 * Useful for testing
 */
declare function restoreConsole(): void;

declare function setupBrowserMocks(): void;

export { APIClientError, API_URL, DEBOUNCE_FILTER, DEBOUNCE_SLIDER, GC_TIME_LONG, GC_TIME_MEDIUM, GC_TIME_SHORT, LIMIT_ACTIVITY_FEED, OAUTH_FLOW_TIMEOUT, PAGE_SIZE_DEFAULT, REFETCH_INTERVAL_DASHBOARD, REFETCH_INTERVAL_REALTIME, REFETCH_INTERVAL_RUNNING, REFETCH_INTERVAL_RUNNING_FAST, ResourceStatusColors, SSE_CLOSE_GRACE_PERIOD, SSE_TOKEN_REFRESH_DELAY, STALE_TIME_ADMIN, STALE_TIME_DEFAULT, STALE_TIME_MONITORING, WS_MAX_RETRIES_BEFORE_ERROR, WS_RECONNECT_BASE_DELAY, WS_RECONNECT_MAX_DELAY, debounce, formatChartAxisDate, formatDate, formatDateTime, formatErrorMessage, formatRelativeTime, formatTimeAgo, getErrorInfo, getErrorTitle, getResourceColor, getResourceIcon, getTimeRangeDates, getTimeRangeLabel, isAPIClientError, restoreConsole, setupBrowserMocks, suppressKnownWarnings, validateEmail };
export type { TablerIcon };
