import tseslint from 'typescript-eslint';

/**
 * Enforces the architecture's working agreements that were previously only
 * documented (CLAUDE.md): no `any`, domain/ stays framework-free, and the
 * dependency direction between contexts (herregistratie → registratie → shared,
 * auth → shared; shared depends on nothing). Boundary rules use path patterns on
 * the import aliases, so they read as the direction statement they enforce.
 */
export default [
  {
    ignores: [
      'dist/**',
      'node_modules/**',
      'storybook-static/**',
      '.angular/**',
      'coverage/**',
      'backend/**',
      // Generated client — owns its own /* eslint-disable */ header.
      'src/app/shared/infrastructure/api-client.ts',
    ],
  },
  {
    files: ['src/**/*.ts'],
    languageOptions: {
      parser: tseslint.parser,
      parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
    },
    plugins: { '@typescript-eslint': tseslint.plugin },
    rules: { '@typescript-eslint/no-explicit-any': 'error' },
  },

  // Tests legitimately use `any` to feed invalid messages/states into reducers.
  {
    files: ['src/**/*.spec.ts'],
    rules: { '@typescript-eslint/no-explicit-any': 'off' },
  },

  // domain/ = pure business rules + types. No Angular, ever.
  {
    files: ['src/app/**/domain/**/*.ts'],
    rules: {
      'no-restricted-imports': [
        'error',
        { patterns: [{ group: ['@angular/*', '@angular/**'], message: 'domain/ must stay framework-free (pure TS) — no Angular imports.' }] },
      ],
    },
  },

  // shared/ is the base layer: it may not depend on any feature context.
  // The dev-only debug panel is the sanctioned exception (it observes every store).
  {
    files: ['src/app/shared/**/*.ts'],
    ignores: ['src/app/shared/ui/debug-state/**'],
    rules: {
      'no-restricted-imports': [
        'error',
        { patterns: [{ group: ['@auth/*', '@registratie/*', '@herregistratie/*', '@brief/*'], message: 'shared/ must not depend on a feature context.' }] },
      ],
    },
  },

  // auth/ may depend only on shared.
  {
    files: ['src/app/auth/**/*.ts'],
    rules: {
      'no-restricted-imports': [
        'error',
        { patterns: [{ group: ['@registratie/*', '@herregistratie/*', '@brief/*'], message: 'auth/ may depend only on shared.' }] },
      ],
    },
  },

  // registratie/ may depend on shared, not on herregistratie (direction points the other way).
  {
    files: ['src/app/registratie/**/*.ts'],
    rules: {
      'no-restricted-imports': [
        'error',
        { patterns: [{ group: ['@herregistratie/*', '@brief/*'], message: 'Dependencies point herregistratie → registratie → shared, never back.' }] },
      ],
    },
  },

  // brief/ (letter composition) is an independent leaf context: it may depend only on shared.
  {
    files: ['src/app/brief/**/*.ts'],
    rules: {
      'no-restricted-imports': [
        'error',
        { patterns: [{ group: ['@auth/*', '@registratie/*', '@herregistratie/*'], message: 'brief/ may depend only on shared.' }] },
      ],
    },
  },
];
