/**
 * SQL language support for CodeMirror 6
 * Wraps @codemirror/lang-sql with sensible defaults
 */

import { sql as cmSql, type SQLConfig } from '@codemirror/lang-sql'
import { type LanguageSupport } from '@codemirror/language'
import { type Completion } from '@codemirror/autocomplete'

/** SQL language support with optional configuration */
export function sql(config?: SQLConfig): LanguageSupport {
  return cmSql(config)
}

/** Common SQL keyword completions */
export const sqlCompletions: Completion[] = [
  { label: 'SELECT', type: 'keyword' },
  { label: 'FROM', type: 'keyword' },
  { label: 'WHERE', type: 'keyword' },
  { label: 'INSERT', type: 'keyword' },
  { label: 'UPDATE', type: 'keyword' },
  { label: 'DELETE', type: 'keyword' },
  { label: 'CREATE', type: 'keyword' },
  { label: 'ALTER', type: 'keyword' },
  { label: 'DROP', type: 'keyword' },
  { label: 'JOIN', type: 'keyword' },
  { label: 'LEFT JOIN', type: 'keyword' },
  { label: 'RIGHT JOIN', type: 'keyword' },
  { label: 'INNER JOIN', type: 'keyword' },
  { label: 'OUTER JOIN', type: 'keyword' },
  { label: 'ON', type: 'keyword' },
  { label: 'GROUP BY', type: 'keyword' },
  { label: 'ORDER BY', type: 'keyword' },
  { label: 'HAVING', type: 'keyword' },
  { label: 'LIMIT', type: 'keyword' },
  { label: 'OFFSET', type: 'keyword' },
  { label: 'DISTINCT', type: 'keyword' },
  { label: 'AS', type: 'keyword' },
  { label: 'AND', type: 'keyword' },
  { label: 'OR', type: 'keyword' },
  { label: 'NOT', type: 'keyword' },
  { label: 'IN', type: 'keyword' },
  { label: 'BETWEEN', type: 'keyword' },
  { label: 'LIKE', type: 'keyword' },
  { label: 'IS NULL', type: 'keyword' },
  { label: 'IS NOT NULL', type: 'keyword' },
  { label: 'ASC', type: 'keyword' },
  { label: 'DESC', type: 'keyword' },
  { label: 'COUNT()', type: 'function' },
  { label: 'SUM()', type: 'function' },
  { label: 'AVG()', type: 'function' },
  { label: 'MIN()', type: 'function' },
  { label: 'MAX()', type: 'function' },
  { label: 'COALESCE()', type: 'function' },
  { label: 'CAST()', type: 'function' },
  { label: 'NOW()', type: 'function' },
]
