import eslint from "@eslint/js";
import { defineConfig, globalIgnores } from "eslint/config";
import { createTypeScriptImportResolver } from "eslint-import-resolver-typescript";
import importX from "eslint-plugin-import-x";
import tseslint from "typescript-eslint";

export default defineConfig([
  globalIgnores([".tailor-sdk/", "seed/", "generated/", "tailor.d.ts"]),
  {
    files: ["**/*.ts"],
    extends: [
      eslint.configs.recommended,
      tseslint.configs.recommendedTypeChecked,
      tseslint.configs.stylisticTypeChecked,
      importX.flatConfigs.recommended,
      importX.flatConfigs.typescript,
    ],
    languageOptions: {
      parserOptions: {
        projectService: true,
        tsconfigRootDir: import.meta.dirname,
      },
    },
    settings: {
      "import-x/resolver-next": [createTypeScriptImportResolver()],
    },
    rules: {
      "import-x/order": "error",
    },
  },
  {
    files: ["**/command/**/*.ts"],
    ignores: ["**/*.test.ts"],
    rules: {
      "no-restricted-imports": [
        "error",
        {
          patterns: [
            {
              regex: "^node:",
              message: "Node.js built-in modules are not allowed in command implementations.",
            },
          ],
        },
      ],
      "no-restricted-syntax": [
        "error",
        {
          selector: "ThrowStatement",
          message: "Use Result type (ok/err) instead of throw in command implementations.",
        },
      ],
    },
  },
  {
    files: ["**/command/update*.ts"],
    ignores: ["**/*.test.ts"],
    rules: {
      // Update command inputs intentionally use type aliases to support lookup-key unions.
      "@typescript-eslint/consistent-type-definitions": "off",
    },
  },
]);
