import { CompletionItem, CompletionItemKind, InsertTextFormat, MarkupKind } from 'vscode-languageserver'
import { NativeTypeConstructors } from '../prisma-schema-wasm/nativeTypes'

//#region MONGODB ONLY
export const autoDefaultCompletion = (items: CompletionItem[]) =>
  items.push({
    label: 'auto()',
    kind: CompletionItemKind.Function,
    documentation: 'Represents default values that are automatically generated by the database.',
    insertText: 'auto()',
    insertTextFormat: InsertTextFormat.Snippet,
  })
//#endregion

//#region COCKROACHDB ONLY
export const sequenceDefaultCompletion = (items: CompletionItem[]) =>
  items.push({
    label: 'sequence()',
    kind: CompletionItemKind.Function,
    documentation:
      'Create a sequence of integers in the underlying database and assign the incremented values to the ID values of the created records based on the sequence.',
  })
//#endregion

export const dbgeneratedDefaultCompletion = (items: CompletionItem[]) =>
  items.push({
    label: 'dbgenerated("")',
    kind: CompletionItemKind.Function,
    documentation:
      'The SQL definition of the default value which is generated by the database. This is not validated by Prisma.',
    insertText: 'dbgenerated("$0")',
    insertTextFormat: InsertTextFormat.Snippet,
  })

export const autoincrementDefaultCompletion = (items: CompletionItem[]) =>
  items.push({
    label: 'autoincrement()',
    kind: CompletionItemKind.Function,
    documentation:
      'Create a sequence of integers in the underlying database and assign the incremented values to the ID values of the created records based on the sequence.',
  })

export const nowDefaultCompletion = (items: CompletionItem[]) =>
  items.push({
    label: 'now()',
    kind: CompletionItemKind.Function,
    documentation: {
      kind: MarkupKind.Markdown,
      value: 'Set a timestamp of the time when a record is created.',
    },
  })

export const uuidDefaultCompletion = (items: CompletionItem[]) =>
  items.push({
    label: 'uuid()',
    kind: CompletionItemKind.Function,
    documentation: {
      kind: MarkupKind.Markdown,
      value:
        'Generate a globally unique identifier based on the [UUID](https://en.wikipedia.org/wiki/Universally_unique_identifier) spec.',
    },
  })

export const cuidDefaultCompletion = (items: CompletionItem[]) =>
  items.push({
    label: 'cuid()',
    kind: CompletionItemKind.Function,
    documentation: {
      kind: MarkupKind.Markdown,
      value: 'Generate a globally unique identifier based on the [cuid](https://github.com/ericelliott/cuid) spec.',
    },
  })

export const nativeFunctionCompletion = (
  items: CompletionItem[],
  element: NativeTypeConstructors,
  documentation: string,
) =>
  items.push({
    label: `${element.name}()`,
    kind: CompletionItemKind.TypeParameter,
    insertText: `${element.name}($0)`,
    documentation: { kind: MarkupKind.Markdown, value: documentation },
    insertTextFormat: InsertTextFormat.Snippet,
  })
