import { T } from '@learnitive/mini-js-utils';
import { narrow } from './common';

// Workspace Commands
export const wsCommands = narrow([
  {
    id: 'command::ws:create-file',
    title: 'New File',
    omniSearch: false,
    dependencies: { services: ['fileSystem', 'navigation', 'projectCollaboration'] },
    args: {
      wsPath: T.String,
      navigate: T.Optional(T.Boolean),
    },
  },
  {
    id: 'command::ws:quick-new-file',
    title: 'Quick New File',
    keywords: ['new', 'create', 'file', 'tex', 'latex', 'quick', 'untitled'],
    dependencies: {
      services: ['workspaceState'],
      commands: ['command::ws:new-file-from-input'],
    },
    omniSearch: 'workspace',
    args: {
      pathPrefix: T.Optional(T.String),
    },
  },
  {
    id: 'command::ws:new-file-from-input',
    title: 'New File',
    omniSearch: false,
    dependencies: {
      services: ['workspaceState', 'fileSystem', 'navigation'],
      commands: ['command::ws:create-file'],
    },
    args: {
      inputPath: T.String,
    },
  },
  {
    id: 'command::ws:create-note',
    title: 'New Note',
    omniSearch: false,
    dependencies: { services: ['fileSystem', 'navigation', 'projectCollaboration'] },
    args: {
      wsPath: T.String,
      // whether to navigate to the newly created note
      navigate: T.Optional(T.Boolean),
    },
  },
  {
    id: 'command::ws:quick-new-note',
    title: 'Quick New Note',
    keywords: ['new', 'create', 'note', 'quick', 'untitled'],
    dependencies: {
      services: ['workspaceState'],
      commands: ['command::ws:new-note-from-input'],
    },
    omniSearch: false,
    args: {
      pathPrefix: T.Optional(T.String),
    },
  },
  {
    id: 'command::ws:new-note-from-input',
    title: 'New Note',
    omniSearch: false,
    dependencies: {
      services: ['workspaceState', 'fileSystem', 'navigation'],
      commands: ['command::ws:create-note'],
    },
    args: {
      inputPath: T.String,
    },
  },

  {
    id: 'command::ws:create-directory',
    title: 'Create Directory',
    omniSearch: false,
    dependencies: {
      services: ['fileSystem', 'projectCollaboration', 'projectStorage'],
      commands: [],
    },
    args: {
      dirWsPath: T.String,
    },
  },
  {
    id: 'command::ws:rename-directory',
    title: 'Rename Directory',
    omniSearch: false,
    dependencies: {
      services: [
        'editorEngine',
        'fileSystem',
        'projectStorage',
        'projectCollaboration',
        'userActivityService',
        'workspaceState',
      ],
    },
    args: {
      oldDirWsPath: T.String,
      newDirWsPath: T.String,
    },
  },
  {
    id: 'command::ws:delete-directory',
    title: 'Delete Directory',
    omniSearch: false,
    dependencies: {
      services: [
        'fileSystem',
        'navigation',
        'projectStorage',
        'projectCollaboration',
        'workspaceState',
      ],
    },
    args: {
      dirWsPath: T.String,
    },
  },

  {
    id: 'command::ws:go-workspace',
    title: 'Go to Workspace',
    omniSearch: false,
    dependencies: { services: ['navigation'] },
    args: {
      wsName: T.String,
    },
  },
  {
    id: 'command::ws:go-ws-path',
    title: 'Go to wsPath',
    omniSearch: false,
    dependencies: {
      services: ['navigation'],
    },
    args: {
      wsPath: T.String,
    },
  },
  {
    id: 'command::ws:delete-workspace',
    title: 'Delete Workspace',
    omniSearch: false,
    dependencies: { services: ['workspaceOps', 'navigation'] },
    args: {
      wsName: T.String,
    },
  },
  {
    id: 'command::ws:delete-ws-path',
    title: 'Delete Note',
    omniSearch: false,
    dependencies: { services: ['fileSystem', 'navigation', 'projectCollaboration'] },
    args: {
      wsPath: T.String,
    },
  },
  {
    id: 'command::ws:delete-ws-paths',
    title: 'Delete Files',
    omniSearch: false,
    dependencies: { services: ['fileSystem', 'navigation', 'projectCollaboration'] },
    args: {
      wsPaths: T.Array(T.String),
    },
  },
  {
    id: 'command::ws:rename-ws-path',
    title: 'Rename Note',
    omniSearch: false,
    dependencies: {
      services: ['editorEngine', 'fileSystem', 'projectCollaboration', 'userActivityService'],
    },
    args: {
      wsPath: T.String,
      newWsPath: T.String,
    },
  },
  {
    id: 'command::ws:move-ws-path',
    title: 'Move Note',
    omniSearch: false,
    dependencies: {
      services: ['editorEngine', 'fileSystem', 'projectCollaboration', 'userActivityService'],
    },
    args: {
      wsPath: T.String,
      destDirWsPath: T.String,
    },
  },
  {
    id: 'command::ws:go-ws-home',
    title: 'Go to Project Home',
    keywords: ['home', 'project', 'workspace', 'go'],
    omniSearch: 'workspace',
    dependencies: { services: ['navigation'] },
    args: null,
  },
  {
    id: 'command::ws:refresh-file-tree',
    title: 'Refresh Files',
    keywords: ['refresh', 'reload', 'rescan', 'files', 'file tree'],
    omniSearch: 'workspace',
    dependencies: { services: ['fileSystem'] },
    args: null,
  },
  {
    id: 'command::ws:clone-note',
    title: 'Duplicate File',
    omniSearch: 'note',
    keywords: ['clone', 'duplicate', 'copy'],
    dependencies: { services: ['workspaceState', 'fileSystem', 'navigation'] },
    args: null,
  },
  {
    id: 'command::ws:recover-note-snapshot',
    title: 'Recover Note Snapshot',
    omniSearch: false,
    dependencies: {
      services: ['noteSnapshot', 'fileSystem', 'navigation'],
    },
    args: {
      snapshotId: T.String,
    },
  },
  {
    id: 'command::ws:daily-note',
    title: 'Open Daily Note',
    keywords: ['daily', 'note', 'today', 'journal'],
    omniSearch: false,
    dependencies: {
      services: ['workspaceState', 'fileSystem', 'navigation'],
      commands: ['command::ws:create-note'],
    },
    args: {
      date: T.Optional(T.Number),
    },
  },
  {
    id: 'command::workspace:toggle-star',
    title: 'Toggle Star for Current File',
    keywords: ['star', 'unstar', 'favorite', 'file', 'toggle', 'project'],
    dependencies: {
      services: ['workspaceState', 'userActivityService'],
    },
    omniSearch: 'note',
    keybindings: ['ctrl', 'shift', 's'],
    args: {
      wsPath: T.Optional(T.String),
    },
  },
]);
