/**
 * Cloud Sync Type Definitions
 *
 * Defines the data structures for the Cloud Sync system that replaces
 * the WebSocket Relay pairing model. All devices under the same Cloud
 * account are automatically visible and can exchange messages.
 *
 * @see docs/cloud-sync-design.md
 * @module services/cloud/cloud-sync.types
 */
/** Valid cloud sync state values for runtime validation. */
export const CLOUD_SYNC_STATES = ['stopped', 'syncing', 'error', 'auth_expired'];
/** Valid message type values for runtime validation. */
export const MESSAGE_TYPES = [
    'command',
    'sync_teams',
    'sync_settings',
    'notification',
    'relay',
    'ping',
    'task_update',
    'agent_message',
    'cross-machine',
    'browser_command',
    'browser_response',
    'chat_request',
    'chat_response',
    'chat_event',
];
/**
 * Check if an object satisfies the AgentMessagePayload interface shape.
 *
 * @param value - Value to check
 * @returns True if the value has the required AgentMessagePayload fields
 */
export function isAgentMessagePayload(value) {
    if (typeof value !== 'object' || value === null)
        return false;
    const obj = value;
    return (typeof obj.targetSession === 'string' &&
        typeof obj.message === 'string' &&
        typeof obj.fromDevice === 'string' &&
        typeof obj.fromDeviceName === 'string');
}
/** Set form for runtime validation. */
export const CHAT_RPC_METHODS = [
    'listAgents',
    'getAgentPresence',
    'listChannels',
    'ensureDmChannel',
    'createChannel',
    'createHuddle',
    'listHuddleMembers',
    'listMessages',
    'sendMessage',
];
/**
 * Best-effort type guard for `chat_request` payloads. Used by the OSS
 * adapter when consuming raw IncomingMessage.payload values before
 * dispatching to ChatV2Service.
 *
 * @param value - Untyped payload from the relay
 * @returns True iff the value has the minimum fields for a valid request
 */
export function isChatRequestPayload(value) {
    if (typeof value !== 'object' || value === null)
        return false;
    const obj = value;
    // Wire shape requires `id` + `method` to both be strings. We intentionally
    // do NOT check `method` against {@link CHAT_RPC_METHODS} here — that's the
    // OSS adapter's job, and rejecting unknown methods at the guard level
    // would drop the message silently. Instead, the adapter responds with
    // a structured `unsupported_method` error so Portal gets a clear signal
    // rather than a hang.
    return typeof obj.id === 'string' && typeof obj.method === 'string';
}
/**
 * Best-effort type guard for `chat_response` payloads. Used by the Portal
 * client to discard malformed responses without throwing inside the
 * inbound-message dispatch loop.
 *
 * @param value - Untyped payload from the relay
 * @returns True iff the value has a string `id` field
 */
export function isChatResponsePayload(value) {
    if (typeof value !== 'object' || value === null)
        return false;
    const obj = value;
    return typeof obj.id === 'string';
}
/**
 * Best-effort type guard for `chat_event` payloads.
 *
 * @param value - Untyped payload from the relay
 * @returns True iff the value has a string `channelId` and an `event` field
 */
export function isChatEventPayload(value) {
    if (typeof value !== 'object' || value === null)
        return false;
    const obj = value;
    return typeof obj.channelId === 'string' && obj.event !== undefined;
}
// ---------------------------------------------------------------------------
// Type Guards
// ---------------------------------------------------------------------------
/**
 * Check if a value is a valid CloudSyncState.
 *
 * @param value - Value to check
 * @returns True if the value is a valid CloudSyncState
 */
export function isCloudSyncState(value) {
    return typeof value === 'string' && CLOUD_SYNC_STATES.includes(value);
}
/**
 * Check if a value is a valid MessageType.
 *
 * @param value - Value to check
 * @returns True if the value is a valid MessageType
 */
export function isMessageType(value) {
    return typeof value === 'string' && MESSAGE_TYPES.includes(value);
}
/**
 * Check if an object satisfies the SyncDevice interface shape.
 *
 * @param value - Value to check
 * @returns True if the value has the required SyncDevice fields
 */
export function isSyncDevice(value) {
    if (typeof value !== 'object' || value === null)
        return false;
    const obj = value;
    return (typeof obj.deviceId === 'string' &&
        typeof obj.deviceName === 'string' &&
        (obj.status === 'online' || obj.status === 'offline') &&
        typeof obj.lastHeartbeatAt === 'string');
}
/**
 * Check if an object satisfies the IncomingMessage interface shape.
 *
 * @param value - Value to check
 * @returns True if the value has the required IncomingMessage fields
 */
export function isIncomingMessage(value) {
    if (typeof value !== 'object' || value === null)
        return false;
    const obj = value;
    return (typeof obj.id === 'string' &&
        typeof obj.from === 'string' &&
        typeof obj.fromDeviceName === 'string' &&
        isMessageType(obj.type) &&
        typeof obj.encrypted === 'boolean' &&
        typeof obj.sentAt === 'string');
}
/**
 * Check if an object satisfies the CloudSyncConfig interface shape.
 *
 * @param value - Value to check
 * @returns True if the value has the required CloudSyncConfig fields
 */
export function isCloudSyncConfig(value) {
    if (typeof value !== 'object' || value === null)
        return false;
    const obj = value;
    return (typeof obj.cloudUrl === 'string' &&
        typeof obj.token === 'string' &&
        typeof obj.deviceId === 'string' &&
        typeof obj.deviceName === 'string');
}
//# sourceMappingURL=cloud-sync.types.js.map