import npmTypes from '@pnpm/npm-conf/lib/types.js'
import { type TrustPolicy } from '@pnpm/types'

export const pnpmTypes = {
  'auto-install-peers': Boolean,
  bail: Boolean,
  ci: Boolean,
  'cache-dir': String,
  'catalog-mode': ['strict', 'prefer', 'manual'],
  'child-concurrency': Number,
  'merge-git-branch-lockfiles': Boolean,
  'merge-git-branch-lockfiles-branch-pattern': Array,
  color: ['always', 'auto', 'never'],
  'config-dir': String,
  'dangerously-allow-all-builds': Boolean,
  'deploy-all-files': Boolean,
  'dedupe-peer-dependents': Boolean,
  'dedupe-direct-deps': Boolean,
  'dedupe-injected-deps': Boolean,
  dev: [null, true],
  dir: String,
  'disallow-workspace-cycles': Boolean,
  'enable-modules-dir': Boolean,
  'enable-pre-post-scripts': Boolean,
  'enable-global-virtual-store': Boolean,
  'exclude-links-from-lockfile': Boolean,
  'extend-node-path': Boolean,
  'fetch-timeout': Number,
  'fetch-warn-timeout-ms': Number,
  'fetch-min-speed-ki-bps': Number,
  'fetching-concurrency': Number,
  filter: [String, Array],
  'filter-prod': [String, Array],
  'force-legacy-deploy': Boolean,
  'frozen-lockfile': Boolean,
  'git-checks': Boolean,
  'git-shallow-hosts': Array,
  'global-bin-dir': String,
  'global-dir': String,
  'global-path': String,
  'global-pnpmfile': String,
  'git-branch-lockfile': Boolean,
  hoist: Boolean,
  'hoist-pattern': Array,
  'hoist-workspace-packages': Boolean,
  'ignore-compatibility-db': Boolean,
  'ignore-dep-scripts': Boolean,
  'ignore-pnpmfile': Boolean,
  'ignore-workspace': Boolean,
  'ignore-workspace-cycles': Boolean,
  'ignore-workspace-root-check': Boolean,
  'optimistic-repeat-install': Boolean,
  'include-workspace-root': Boolean,
  'init-package-manager': Boolean,
  'init-type': ['commonjs', 'module'],
  'inject-workspace-packages': Boolean,
  'legacy-dir-filtering': Boolean,
  'link-workspace-packages': [Boolean, 'deep'],
  lockfile: Boolean,
  'lockfile-dir': String,
  'lockfile-directory': String, // TODO: deprecate
  'lockfile-include-tarball-url': Boolean,
  'lockfile-only': Boolean,
  loglevel: ['silent', 'error', 'warn', 'info', 'debug'],
  'manage-package-manager-versions': Boolean,
  maxsockets: Number,
  'modules-cache-max-age': Number,
  'dlx-cache-max-age': Number,
  'minimum-release-age': Number,
  'minimum-release-age-exclude': [String, Array],
  'modules-dir': String,
  'network-concurrency': Number,
  'node-linker': ['pnp', 'isolated', 'hoisted'],
  noproxy: String,
  'npm-path': String,
  offline: Boolean,
  'only-built-dependencies': [String, Array],
  'pack-destination': String,
  'pack-gzip-level': Number,
  'package-import-method': ['auto', 'hardlink', 'clone', 'copy'],
  'patches-dir': String,
  pnpmfile: String,
  'package-manager-strict': Boolean,
  'package-manager-strict-version': Boolean,
  'prefer-frozen-lockfile': Boolean,
  'prefer-offline': Boolean,
  'prefer-symlinked-executables': Boolean,
  'prefer-workspace-packages': Boolean,
  'preserve-absolute-paths': Boolean,
  production: [null, true],
  'public-hoist-pattern': Array,
  'publish-branch': String,
  'recursive-install': Boolean,
  reporter: String,
  'resolution-mode': ['highest', 'time-based', 'lowest-direct'],
  'resolve-peers-from-workspace-root': Boolean,
  'aggregate-output': Boolean,
  'reporter-hide-prefix': Boolean,
  'save-peer': Boolean,
  'save-catalog-name': String,
  'save-workspace-protocol': Boolean,
  'script-shell': String,
  'shamefully-flatten': Boolean,
  'shamefully-hoist': Boolean,
  'shared-workspace-lockfile': Boolean,
  'shell-emulator': Boolean,
  'side-effects-cache': Boolean,
  'side-effects-cache-readonly': Boolean,
  symlink: Boolean,
  sort: Boolean,
  'state-dir': String,
  'store-dir': String,
  stream: Boolean,
  'strict-dep-builds': Boolean,
  'strict-store-pkg-content-check': Boolean,
  'strict-peer-dependencies': Boolean,
  'trust-policy': ['off', 'no-downgrade'] satisfies TrustPolicy[],
  'trust-policy-exclude': [String, Array],
  'use-beta-cli': Boolean,
  'use-node-version': String,
  'use-running-store-server': Boolean,
  'use-store-server': Boolean,
  'use-stderr': Boolean,
  'verify-deps-before-run': Boolean,
  'verify-store-integrity': Boolean,
  'global-virtual-store-dir': String,
  'virtual-store-dir': String,
  'virtual-store-dir-max-length': Number,
  'peers-suffix-max-length': Number,
  'workspace-concurrency': Number,
  'workspace-packages': [String, Array],
  'workspace-root': Boolean,
  'test-pattern': [String, Array],
  'changed-files-ignore-pattern': [String, Array],
  'embed-readme': Boolean,
  'update-notifier': Boolean,
  'registry-supports-time-field': Boolean,
  'fail-if-no-match': Boolean,
  'sync-injected-deps-after-scripts': Array,
  cpu: [String, Array],
  libc: [String, Array],
  os: [String, Array],
}

// NOTE: There is an oversight I just now notice thanks to a test failure: pnpmTypes (which used to be the object literal inside `Object.assign`)
//       contains some field that overlaps with that of `npmTypes.types`. The definitions of such fields are pointless as they are overwritten by
//       `npmTypes.types` anyway.
// TODO: Fix this overlap later.
// TODO: After that, move `...pnpmTypes` down, `...npmTypes.types` up.
export const types = {
  ...pnpmTypes,
  ...npmTypes.types,
}
