/**
 * Tool registry – wires every MCP tool into the server.
 */

import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import type { ToolContext } from '../types';
import { registerSapConnectTool } from './sap-connect';
import { registerSapDisconnectTool } from './sap-disconnect';
import { registerChangesetBeginTool } from './changeset-begin';
import { registerChangesetAddTool } from './changeset-add';
import { registerChangesetCommitTool } from './changeset-commit';
import { registerChangesetRollbackTool } from './changeset-rollback';
import { registerDiscoveryTool } from './discovery';
import { registerSystemInfoTool } from './system-info';
import { registerSearchObjectsTool } from './search-objects';
import { registerGetObjectTool } from './get-object';
import { registerCtsListTransportsTool } from './cts-list-transports';
import { registerCtsGetTransportTool } from './cts-get-transport';
import { registerCtsCreateTransportTool } from './cts-create-transport';
import { registerCtsCreateTaskTool } from './cts-create-task';
import { registerCtsReleaseTransportTool } from './cts-release-transport';
import { registerCtsDeleteTransportTool } from './cts-delete-transport';
import { registerCtsSearchTransportsTool } from './cts-search-transports';
import { registerAtcRunTool } from './atc-run';
import { registerGetSourceTool } from './get-source';
import { registerGetFrozenSourceTool } from './get-frozen-source';
import { registerUpdateSourceTool } from './update-source';
import { registerLintAbapTool } from './lint-abap';
import { registerActivateObjectTool } from './activate-object';
import { registerCheckSyntaxTool } from './check-syntax';
import { registerRunUnitTestsTool } from './run-unit-tests';
import { registerGetTestClassesTool } from './get-test-classes';
import { registerListPackageObjectsTool } from './list-package-objects';
// New tools – high-priority feature parity (#H1–#H8)
import { registerGrepObjectsTool } from './grep-objects';
import { registerGrepPackagesTool } from './grep-packages';
import { registerGetTableTool } from './get-table';
import { registerGetTableContentsTool } from './get-table-contents';
import { registerRunQueryTool } from './run-query';
import { registerFindDefinitionTool } from './find-definition';
import { registerFindReferencesTool } from './find-references';
import {
  registerGetCallersOfTool,
  registerGetCalleesOfTool,
} from './call-hierarchy';
import { registerCreateObjectTool } from './create-object';
import { registerDeleteObjectTool } from './delete-object';
import { registerActivatePackageTool } from './activate-package';
// Medium-priority feature parity (#M1–#M10)
import {
  registerGetFunctionGroupTool,
  registerGetFunctionTool,
} from './function-tools';
import { registerCreateFunctionGroupTool } from './create-function-group';
import { registerCreateFunctionModuleTool } from './create-function-module';
import { registerDeleteFunctionModuleTool } from './delete-function-module';
import { registerLockObjectTool } from './lock-object';
import { registerUnlockObjectTool } from './unlock-object';
import { registerGetObjectStructureTool } from './get-object-structure';
import { registerGetTypeHierarchyTool } from './get-type-hierarchy';
import { registerPrettyPrintTool } from './pretty-print';
import { registerGetContextTool } from './get-context';
import { registerGetShortDumpsTool } from './get-short-dumps';
import { registerGetTracesTool } from './get-traces';
import { registerGetCompletionsTool } from './get-completions';
import { registerCreatePackageTool } from './create-package';
import {
  registerGetInstalledComponentsTool,
  registerGetFeaturesTool,
} from './get-installed-components';
import { registerCloneObjectTool } from './clone-object';
import { registerPublishServiceBindingTool } from './publish-service-binding';
import { registerGetGitTypesTool, registerGitExportTool } from './git-tools';
import { registerRunAbapTool } from './run-abap';
import { registerGetDomainTool } from './get-domain';
import { registerGetIncludeTool } from './get-include';
import { registerGetDataElementTool } from './get-data-element';
import { registerGetStructureTool } from './get-structure';
import { registerGetCdsDdlTool } from './get-cds-ddl';
import { registerGetCdsDclTool } from './get-cds-dcl';
import { registerGetBdefTool } from './get-bdef';
import { registerCreateBdefTool } from './create-bdef';
import { registerDeleteBdefTool } from './delete-bdef';
import { registerGetBadiTool } from './get-badi';
import { registerCreateBadiTool } from './create-badi';
import { registerDeleteBadiTool } from './delete-badi';
import { registerGetSrvdTool } from './get-srvd';
import { registerCreateSrvdTool } from './create-srvd';
import { registerDeleteSrvdTool } from './delete-srvd';
import { registerGetSrvbTool } from './get-srvb';
import { registerCreateSrvbTool } from './create-srvb';
import { registerDeleteSrvbTool } from './delete-srvb';
import { registerUnpublishSrvbTool } from './unpublish-srvb';
// CTS + package parity tools
import { registerCtsUpdateTransportTool } from './cts-update-transport';
import { registerCtsReassignTransportTool } from './cts-reassign-transport';
import { registerCtsTransportObjectsTool } from './cts-transport-objects';
import { registerStatPackageTool } from './stat-package';
import { registerGetPackageTool } from './get-package';
import { registerLookupUserTool } from './lookup-user';
// Import tools – mirror `adt import object|package|transport`
import { registerImportObjectTool } from './import-object';
import { registerImportPackageTool } from './import-package';
import { registerImportTransportTool } from './import-transport';
// STRUST — SSL PSE cert management
import { registerListPsesTool } from './list-pses';
import { registerListCertsTool } from './list-certs';
import { registerUploadCertTool } from './upload-cert';
import { registerDeleteCertTool } from './delete-cert';
// Checkin (E08) — inverse of import_package; pushes local files → SAP.
import { registerCheckinTool } from './checkin';
// gCTS (E07) — /sap/bc/cts_abapvcs/* surface (separate from /sap/bc/adt)
import { registerGctsTools } from './gcts-tools';
// RFC (E13) — classic RFC function modules via SOAP-over-HTTP
import { registerCallRfcTool } from './call-rfc';
// FLP (E14) — Fiori Launchpad inventory (Page Builder OData)
import { registerListFlpCatalogsTool } from './list-flp-catalogs';
import { registerListFlpGroupsTool } from './list-flp-groups';
import { registerListFlpTilesTool } from './list-flp-tiles';
import { registerGetFlpTileTool } from './get-flp-tile';
// Exact source history — metadata listing, explicit immutable source read,
// and component-granular CTS manifests.
import { registerListSourceVersionsTool } from './list-source-versions';
import { registerGetSourceVersionTool } from './get-source-version';
import { registerCtsTransportSourceManifestTool } from './cts-transport-source-manifest';
import { registerFlowCheckoutTrTool } from './flow-checkout-tr';

export function registerTools(server: McpServer, ctx: ToolContext): void {
  // Session lifecycle tools (HTTP transport only)
  registerSapConnectTool(server, ctx);
  registerSapDisconnectTool(server, ctx);
  // Wave 3 — transactional changesets (HTTP transport only)
  registerChangesetBeginTool(server, ctx);
  registerChangesetAddTool(server, ctx);
  registerChangesetCommitTool(server, ctx);
  registerChangesetRollbackTool(server, ctx);
  // Existing tools
  registerDiscoveryTool(server, ctx);
  registerSystemInfoTool(server, ctx);
  registerSearchObjectsTool(server, ctx);
  registerGetObjectTool(server, ctx);
  registerCtsListTransportsTool(server, ctx);
  registerCtsGetTransportTool(server, ctx);
  registerCtsCreateTransportTool(server, ctx);
  registerCtsCreateTaskTool(server, ctx);
  registerCtsReleaseTransportTool(server, ctx);
  registerCtsDeleteTransportTool(server, ctx);
  registerCtsSearchTransportsTool(server, ctx);
  registerAtcRunTool(server, ctx);
  registerGetFrozenSourceTool(server, ctx);
  registerGetSourceTool(server, ctx);
  registerUpdateSourceTool(server, ctx);
  registerLintAbapTool(server, ctx);
  registerGetContextTool(server, ctx);
  registerActivateObjectTool(server, ctx);
  registerCheckSyntaxTool(server, ctx);
  registerRunUnitTestsTool(server, ctx);
  registerGetTestClassesTool(server, ctx);
  registerListPackageObjectsTool(server, ctx);
  // New tools – feature parity with vibing-steampunk (#H1–#H8)
  registerGrepObjectsTool(server, ctx);
  registerGrepPackagesTool(server, ctx);
  registerGetTableTool(server, ctx);
  registerGetTableContentsTool(server, ctx);
  registerRunQueryTool(server, ctx);
  registerFindDefinitionTool(server, ctx);
  registerFindReferencesTool(server, ctx);
  registerGetCallersOfTool(server, ctx);
  registerGetCalleesOfTool(server, ctx);
  registerCreateObjectTool(server, ctx);
  registerDeleteObjectTool(server, ctx);
  registerActivatePackageTool(server, ctx);
  // Medium-priority tools (#M1–#M10)
  registerGetFunctionGroupTool(server, ctx);
  registerGetFunctionTool(server, ctx);
  registerCreateFunctionGroupTool(server, ctx);
  registerCreateFunctionModuleTool(server, ctx);
  registerDeleteFunctionModuleTool(server, ctx);
  registerLockObjectTool(server, ctx);
  registerUnlockObjectTool(server, ctx);
  registerGetObjectStructureTool(server, ctx);
  registerGetTypeHierarchyTool(server, ctx);
  registerPrettyPrintTool(server, ctx);
  registerGetShortDumpsTool(server, ctx);
  registerGetTracesTool(server, ctx);
  registerGetCompletionsTool(server, ctx);
  registerCreatePackageTool(server, ctx);
  registerGetInstalledComponentsTool(server, ctx);
  registerGetFeaturesTool(server, ctx);
  registerCloneObjectTool(server, ctx);
  registerPublishServiceBindingTool(server, ctx);
  registerGetGitTypesTool(server, ctx);
  registerGitExportTool(server, ctx);
  // Import tools
  registerImportObjectTool(server, ctx);
  registerImportPackageTool(server, ctx);
  registerImportTransportTool(server, ctx);
  // CTS + package parity tools
  registerCtsUpdateTransportTool(server, ctx);
  registerCtsReassignTransportTool(server, ctx);
  registerCtsTransportObjectsTool(server, ctx);
  registerStatPackageTool(server, ctx);
  registerGetPackageTool(server, ctx);
  registerLookupUserTool(server, ctx);
  // DDIC/CDS read tools + ABAP run
  registerRunAbapTool(server, ctx);
  registerGetDomainTool(server, ctx);
  registerGetIncludeTool(server, ctx);
  registerGetDataElementTool(server, ctx);
  registerGetStructureTool(server, ctx);
  registerGetCdsDdlTool(server, ctx);
  registerGetCdsDclTool(server, ctx);
  registerGetBdefTool(server, ctx);
  registerCreateBdefTool(server, ctx);
  registerDeleteBdefTool(server, ctx);
  registerGetBadiTool(server, ctx);
  registerCreateBadiTool(server, ctx);
  registerDeleteBadiTool(server, ctx);
  registerGetSrvdTool(server, ctx);
  registerCreateSrvdTool(server, ctx);
  registerDeleteSrvdTool(server, ctx);
  registerGetSrvbTool(server, ctx);
  registerCreateSrvbTool(server, ctx);
  registerDeleteSrvbTool(server, ctx);
  registerUnpublishSrvbTool(server, ctx);
  // STRUST — PSE cert management (E04)
  registerListPsesTool(server, ctx);
  registerListCertsTool(server, ctx);
  registerUploadCertTool(server, ctx);
  registerDeleteCertTool(server, ctx);
  // Checkin (E08)
  registerCheckinTool(server, ctx);
  // gCTS (E07) — /sap/bc/cts_abapvcs/*
  registerGctsTools(server, ctx);
  // RFC (E13) — SOAP-over-HTTP RFC function module calls
  registerCallRfcTool(server, ctx);
  // FLP (E14) — Page Builder OData catalog/group/tile inventory
  registerListFlpCatalogsTool(server, ctx);
  registerListFlpGroupsTool(server, ctx);
  registerListFlpTilesTool(server, ctx);
  registerGetFlpTileTool(server, ctx);
  // Exact source history
  registerListSourceVersionsTool(server, ctx);
  registerGetSourceVersionTool(server, ctx);
  registerCtsTransportSourceManifestTool(server, ctx);
  registerFlowCheckoutTrTool(server, ctx);
}
