import globals from 'globals'
import pluginJs from '@eslint/js'
import tseslint from 'typescript-eslint'
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended'
import noOnlyTests from 'eslint-plugin-no-only-tests'
// import eslintPluginPrettier from 'eslint-plugin-prettier'

// import eslintConfigPrettier from 'eslint-config-prettier'

/**
 * List of files that must be ignored globally
 */
export const GLOBAL_IGNORE_LIST = [
  '.github/',
  '.husky/',
  '.tmp/',
  '.rollup.cache/',
  '.vscode/',
  '.wireit/',
  'amf-models/',
  'build/',
  'coverage/',
  'node_modules',
  'scripts/',
  // 'test/',
  // 'eslint.config.js',
  '*.min.*',
  '*.d.ts',
  'CHANGELOG.md',
  'dist/**',
  'LICENSE*',
  'coverage/**',
  'package-lock.json',
]

/** @type {import('eslint').Linter.Config[]} */
export default [
  pluginJs.configs.recommended,
  ...tseslint.configs.strict,
  ...tseslint.configs.stylistic,
  // eslintConfigPrettier,
  eslintPluginPrettierRecommended,
  {
    files: ['**/*.ts'],
    languageOptions: {
      globals: {
        ...globals.browser,
      },
      sourceType: 'module',
    },
    rules: {
      'no-restricted-globals': [
        'error',
        ...Object.keys(globals.node).filter(
          // Disallow Node-specific globals (unless they are shared)
          (g) => !Object.prototype.hasOwnProperty.call(globals.browser, g)
        ),
      ],
      'max-len': [
        'error',
        {
          code: 120,
          comments: 120,
          ignoreUrls: true,
          ignoreTemplateLiterals: true,
        },
      ],
      'no-unreachable': ['error'],
      'no-multi-spaces': ['error'],
      'no-console': ['error'],
      'no-redeclare': ['error'],
    },
  },
  {
    files: [
      'tests/**/*.ts',
      'src/runtime/{http-engine,http-runner,node,reporters}/**/*.ts',
      'src/proxy/**/*.ts',
      'src/Platform.ts',
      'src/lib/transformers/PayloadSerializer.ts',
      'src/models/SerializablePayload.ts',
      'src/lib/calculators/DataCalculator.ts',
      'src/lib/Buffer.ts',
      'src/events/amf/AmfEvents.ts',
      'src/authorization/lib/SecurityProcessor.ts',
    ],
    languageOptions: {
      globals: {
        ...globals.node, // Enable Node.js globals for these files
      },
    },
    rules: {
      'no-restricted-globals': [
        'error',
        ...Object.keys(globals.browser).filter(
          // Disallow Node-specific globals (unless they are shared)
          (g) => !Object.prototype.hasOwnProperty.call(globals.node, g)
        ),
      ],
    },
  },
  {
    files: ['tests/**/*.ts', 'test/**/*.ts'],
    plugins: {
      'no-only-tests': noOnlyTests,
    },
    rules: {
      '@typescript-eslint/no-non-null-assertion': 'off',
      '@typescript-eslint/no-empty-function': 'off',
      'no-only-tests/no-only-tests': 'error',
      'no-console': ['warn'],
    },
  },
  {
    ignores: GLOBAL_IGNORE_LIST,
  },
  // {
  //   name: 'Plugins list',
  //   plugins: {
  //     // ...eslintPluginPrettierRecommended.plugins,
  //     ...eslintConfigPrettier.plugins,
  //     prettier: eslintPluginPrettier,
  //   },
  // },
]
