/**
 * @file constants.ts - Application-wide constants for authentication, session management, storage keys, WebSocket configuration, validation limits, and file upload constraints.
 */

// Cross-tab authentication session synchronization (BroadcastChannel)
export const AUTH_SESSION_SYNC_CHANNEL_NAME = 'authChannel';
export const AUTH_SESSION_SYNC_RECEIVED_EVENT_NAME = 'authSessionReceived';
export const AUTH_SESSION_SYNC_UPDATED_EVENT_NAME = 'authSessionUpdated';
export const AUTH_SESSION_SYNC_REFRESHED_EVENT_NAME = 'authSessionRefreshed';
export const AUTH_SESSION_SYNC_TIMEOUT = 150; // 150 milliseconds
export const AUTH_SESSION_SYNC_MIN_LOADING_DISPLAY_TIME =
  AUTH_SESSION_SYNC_TIMEOUT * 2; // 300 milliseconds
export const AUTH_SESSION_SYNC_OWNERSHIP_FALLBACK_DELAY = 5000; // 5 seconds

// Session storage keys for current authentication credentials
export const SESSION_STORAGE_USER = 'currentUser';
export const SESSION_STORAGE_TOKEN = 'accessToken';
export const SESSION_STORAGE_REFRESH = 'refreshToken';

// JWT token lifecycle timing
export const TOKEN_LIFETIME = 15 * 60 * 1000; // 15 minutes
export const REFRESH_INTERVAL = TOKEN_LIFETIME * 0.8; // 12 minutes
export const INACTIVITY_TIMEOUT = TOKEN_LIFETIME * 0.9; // 13.5 minutes

// IWS5 API JWT claims
export const IWS5_JWT_ROLE_CLAIMS_PROPERTY_KEY =
  'http://schemas.microsoft.com/ws/2008/06/identity/claims/role';
export const PD_USER_GROUP_NAME = 'PDUserGroup';

// Session and local storage keys for user preferences
export const SESSION_STORAGE_SELECTED_PROCESS = 'selectedProcessId';
export const SESSION_STORAGE_SELECTED_QUEUE = 'selectedQueueId';
export const LOCAL_STORAGE_AUTO_SAVE_MODE = 'autoSaveMode';
export const LOCAL_STORAGE_AUTO_OPEN_MODE = 'autoOpenMode';
export const LOCAL_STORAGE_EXPAND_INBOX_CARD = 'expandInboxCard';
export const LOCAL_STORAGE_PAGINATION_INBOX_TABLE = 'inboxTablePagination';
export const LOCAL_STORAGE_PAGINATION_QUEUE_TABLE = 'queueTablePagination';
export const LOCAL_STORAGE_QUEUE_SHOW_FOLDER_FIELDS = 'queueShowFolderFields';

// RWP Companion desktop app WebSocket connection settings
export const WEBSOCKET_PROTOCOL = 'ws';
export const WEBSOCKET_HOST = 'localhost';
export const RWP_COMPANION_WEBSOCKET_PORT = 8181;
export const RWP_COMPANION_WEBSOCKET_ADDRESS =
  WEBSOCKET_PROTOCOL +
  '://' +
  WEBSOCKET_HOST +
  ':' +
  RWP_COMPANION_WEBSOCKET_PORT;

// Validation limits for form fields and file uploads
export const MAX_WORK_ITEM_NAME_LENGTH = 255;
export const MAX_FOLDER_FIELD_LENGTH = 255;
export const MAX_DOCUMENT_TEMPLATE_FIELD_LENGTH = 255;
export const MAX_NOTE_LENGTH = 1024;
export const MAX_FILE_NAME_LENGTH = 255;
export const MAX_FILE_SIZE = 25 * 1024 * 1024; // 25 MB
export const DEFAULT_DOCUMENT_TEMPLATE_ID = 1;
export const DEFAULT_DOCUMENT_TEMPLATE_NAME = 'DefaultTemplate';
type FileExtension = { mimeType: string; extensions: string[] };
export const UPLOAD_ACCEPTED_FILE_EXTENSIONS: FileExtension[] = [
  { mimeType: 'application/pdf', extensions: ['.pdf'] },
];
export const SIGNAGE_ACCEPTED_CERTIFICATE_FILE_EXTENSIONS = [
  '.key',
  '.pem',
  '.crt',
  '.cer',
  '.der',
  '.p12',
  '.pfx',
  '.p7b',
  '.p7c',
  '.jks',
  '.keystore',
  '.truststore',
  '.pk8',
  '.pub',
  '.ppk',
  '.csr',
  '.asc',
  '.gpg',
  '.ssh',
];

// Divisor applied to stamp image dimensions when placing annotations in the PDF viewer
export const CUSTOM_STAMP_ANNOTATION_SIZE_DIVISOR = 4;
