/**
 * Filevine Plugin Constants
 * 
 * IMPORTANT: These values were discovered through testing and are NOT
 * in Filevine's public documentation. See docs/DESIGN.md for details.
 */

// API Configuration
export const API_BASE_URL = 'https://api.filevineapp.com/fv-app/v2';
export const IDENTITY_URL = 'https://identity.filevine.com';
export const TOKEN_ENDPOINT = `${IDENTITY_URL}/connect/token`;

// CRITICAL: Use PascalCase for all endpoints
export const ENDPOINTS = {
  GET_USER_ORGS: '/utils/GetUserOrgsWithToken',
  PROJECTS: '/Projects',
  PROJECT: (id) => `/Projects/${id}`,
  PROJECT_DOCS: (projectId) => `/Projects/${projectId}/Docs`,
  DOC_DOWNLOAD: (docId) => `/Docs/${docId}/Download`,
  CONTACTS: '/Contacts',
  PROJECT_TYPES: '/ProjectTypes',
};

// Required OAuth scopes
export const OAUTH_SCOPES = [
  'fv.api.gateway.access',
  'tenant',
  'filevine.v2.api.*',
  'email',
  'openid',
  'fv.auth.tenant.read'
].join(' ');

// Rate limiting
export const RATE_LIMITS = {
  BURST_PER_MINUTE: 100,
  SUSTAINED_PER_HOUR: 600,
  RETRY_DELAY_MS: 1000,
  MAX_RETRIES: 3,
};

// Storage keys
export const STORAGE_KEYS = {
  AUTH: 'fv_auth',
  CURRENT_ORG: 'fv_current_org',
  DOWNLOAD_QUEUE: 'fv_download_queue',
  USER_PREFS: 'fv_user_prefs',
};

// Message types for extension communication
export const MESSAGE_TYPES = {
  // Auth
  AUTH_STATE_CHANGED: 'auth_state_changed',
  AUTH_DETECTED: 'auth_detected',
  AUTH_EXPIRED: 'auth_expired',
  GET_AUTH_STATE: 'get_auth_state',
  
  // API
  API_REQUEST: 'api_request',
  API_RESPONSE: 'api_response',
  
  // Downloads
  DOWNLOAD_FILE: 'download_file',
  DOWNLOAD_PROGRESS: 'download_progress',
  DOWNLOAD_COMPLETE: 'download_complete',
  DOWNLOAD_ERROR: 'download_error',
  
  // Projects
  GET_PROJECTS: 'get_projects',
  GET_PROJECT_DOCS: 'get_project_docs',
  GET_FOLDER_TREE: 'get_folder_tree',
  GET_CURRENT_PROJECT: 'get_current_project',
  
  // Bulk operations
  DOWNLOAD_FOLDER: 'download_folder',
  OPEN_FOLDER_AS_DICOM: 'open_folder_as_dicom', // Open folder as DICOM series
  
  // Viewer
  OPEN_VIEWER: 'open_viewer',
  VIEW_FILE_DIRECT: 'view_file_direct', // Open file directly without downloading

  // Multi-session management
  GET_ACTIVE_SESSIONS: 'get_active_sessions',
  SWITCH_TO_SESSION: 'switch_to_session',
  SESSION_LIST_UPDATED: 'session_list_updated',
};

// File types and their viewers
export const VIEWER_TYPES = {
  DICOM: {
    id: 'dicom',
    name: 'DICOM Viewer',
    extensions: ['.dcm', '.dicom'],
    mimeTypes: ['application/dicom'],
  },
  // Future viewers can be added here
  PDF: {
    id: 'pdf',
    name: 'PDF Viewer',
    extensions: ['.pdf'],
    mimeTypes: ['application/pdf'],
  },
};

// Connection states
export const CONNECTION_STATE = {
  DISCONNECTED: 'disconnected',
  DETECTING: 'detecting',
  CONNECTED: 'connected',
  ERROR: 'error',
};
