// Types for the Notes/Scratchpad feature
// Simplified from full project management to a brainstorming workspace

export type PlaygroundMode = 'docs' | 'api_client' | 'notes'

// File types supported in the notes workspace
export type NoteFileType = 
  | 'javascript'
  | 'typescript' 
  | 'python'
  | 'go'
  | 'ruby'
  | 'php'
  | 'shell'      // curl, bash
  | 'markdown'
  | 'mermaid'    // Diagrams
  | 'json'
  | 'yaml'
  | 'text'

// Single workspace per API (not multiple projects)
export interface Workspace {
  id: string              // Hash of API spec URL
  name: string            // e.g., "Vrio API Notes"
  apiSpecUrl?: string
  createdAt: Date
  updatedAt: Date
}

// A note/file in the workspace
export interface NoteFile {
  id: string
  workspaceId: string
  path: string            // e.g., "auth/oauth-example.py"
  content: string
  createdAt: Date
  updatedAt: Date
}

// Editor state for the workspace
export interface EditorState {
  workspaceId: string
  openTabs: string[]      // File paths
  activeTab: string | null
  cursorPositions: Record<string, { line: number; column: number }>
  scrollPositions: Record<string, number>
}

// Helper to detect file type from path
export function getFileType(path: string): NoteFileType {
  const ext = path.split('.').pop()?.toLowerCase() || ''
  
  const typeMap: Record<string, NoteFileType> = {
    'js': 'javascript',
    'mjs': 'javascript',
    'jsx': 'javascript',
    'ts': 'typescript',
    'tsx': 'typescript',
    'py': 'python',
    'go': 'go',
    'rb': 'ruby',
    'php': 'php',
    'sh': 'shell',
    'bash': 'shell',
    'curl': 'shell',
    'md': 'markdown',
    'mdx': 'markdown',
    'mmd': 'mermaid',
    'mermaid': 'mermaid',
    'json': 'json',
    'yaml': 'yaml',
    'yml': 'yaml',
    'txt': 'text',
  }
  
  return typeMap[ext] || 'text'
}

// Helper to get Monaco language from file type
export function getMonacoLanguage(path: string): string {
  const type = getFileType(path)
  
  const languageMap: Record<NoteFileType, string> = {
    'javascript': 'javascript',
    'typescript': 'typescript',
    'python': 'python',
    'go': 'go',
    'ruby': 'ruby',
    'php': 'php',
    'shell': 'shell',
    'markdown': 'markdown',
    'mermaid': 'markdown',  // Use markdown for mermaid editing
    'json': 'json',
    'yaml': 'yaml',
    'text': 'plaintext',
  }
  
  return languageMap[type]
}

// Check if file type supports preview
export function supportsPreview(path: string): boolean {
  const type = getFileType(path)
  return type === 'markdown' || type === 'mermaid'
}
