///////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2002-2026, Open Design Alliance (the "Alliance").
// All rights reserved.
//
// This software and its documentation and related materials are owned by
// the Alliance. The software may only be incorporated into application
// programs owned by members of the Alliance, subject to a signed
// Membership Agreement and Supplemental Software License Agreement with the
// Alliance. The structure and organization of this software are the valuable
// trade secrets of the Alliance and its suppliers. The software is also
// protected by copyright law and international treaty provisions. Application
// programs incorporating this software must include the following statement
// with their copyright notices:
//
//   This application incorporates Open Design Alliance software pursuant to a
//   license agreement with Open Design Alliance.
//   Open Design Alliance Copyright (C) 2002-2026 by Open Design Alliance.
//   All rights reserved.
//
// By use of this software, its documentation or related materials, you
// acknowledge and accept the above terms.
///////////////////////////////////////////////////////////////////////////////

import { ICommandsRegistry, commandsRegistry } from "@inweb/viewer-core";

import { applyModelTransform } from "./ApplyModelTransform";
import { clearMarkup } from "./ClearMarkup";
import { clearSelected } from "./ClearSelected";
import { clearSlices } from "./ClearSlices";
import { getSnapshot } from "./GetSnapshot";
import { explode, collect } from "./Explode";
import { getDefaultViewPositions } from "./GetDefaultViewPositions";
import { getModels } from "./GetModels";
import { getSelected } from "./GetSelected";
import { getSelected2 } from "./GetSelected2";
import { hideSelected } from "./HideSelected";
import { isolateSelected } from "./IsolateSelected";
import { regenerateAll } from "./RegenerateAll";
import { resetView } from "./ResetView";
import { selectModel } from "./SelectModel";
import { setActiveDragger } from "./SetActiveDragger";
import { setDefaultViewPosition } from "./SetDefaultViewPosition";
import { setMarkupColor } from "./SetMarkupColor";
import { setSelected } from "./SetSelected";
import { setSelected2 } from "./SetSelected2";
import { showAll } from "./ShowAll";
import { zoomToExtents } from "./ZoomToExtents";
import { zoomToObjects } from "./ZoomToObjects";
import { zoomToSelected } from "./ZoomToSelected";

/**
 * Viewer commands registry. Use this registry to register custom commands.
 *
 * To implement custom command:
 *
 * 1. Define a command handler with a first `viewer` parameter.
 * 2. Register command handler in the commands registry by calling the {@link commands.registerCommand}.
 *
 * @example Implementing a custom command.
 *
 * ```javascript
 * import { commands, Viewer } from "@inweb/viewer-three";
 *
 * function commandHandler(viewer: Viewer, name = "world"): void {
 *   console.log(`Hello ${name}!!!`);
 * }
 *
 * commands.registerCommand("sayHello", commandHandler);
 * ```
 *
 * @example Calling a custom command.
 *
 * ```javascript
 * viewer.executeCommand("sayHello", "user");
 * ```
 */
export const commands: ICommandsRegistry = commandsRegistry("threejs");

// build-in commands

commands.registerCommand("applyModelTransform", applyModelTransform);
commands.registerCommand("clearMarkup", clearMarkup);
commands.registerCommand("clearSelected", clearSelected);
commands.registerCommand("clearSlices", clearSlices);
commands.registerCommand("collect", collect);
commands.registerCommand("getSnapshot", getSnapshot);
commands.registerCommand("explode", explode);
commands.registerCommand("getDefaultViewPositions", getDefaultViewPositions);
commands.registerCommand("getModels", getModels);
commands.registerCommand("getSelected", getSelected);
commands.registerCommand("getSelected2", getSelected2);
commands.registerCommand("hideSelected", hideSelected);
commands.registerCommand("isolateSelected", isolateSelected);
commands.registerCommand("regenerateAll", regenerateAll);
commands.registerCommand("resetView", resetView);
commands.registerCommand("selectModel", selectModel);
commands.registerCommand("setActiveDragger", setActiveDragger);
commands.registerCommand("setDefaultViewPosition", setDefaultViewPosition);
commands.registerCommand("setMarkupColor", setMarkupColor);
commands.registerCommand("setSelected", setSelected);
commands.registerCommand("setSelected2", setSelected2);
commands.registerCommand("showAll", showAll);
commands.registerCommand("zoomToExtents", zoomToExtents);
commands.registerCommand("zoomToObjects", zoomToObjects);
commands.registerCommand("zoomToSelected", zoomToSelected);

commands.registerCommand("top", (viewer) => setDefaultViewPosition(viewer, "top"));
commands.registerCommand("bottom", (viewer) => setDefaultViewPosition(viewer, "bottom"));
commands.registerCommand("left", (viewer) => setDefaultViewPosition(viewer, "left"));
commands.registerCommand("right", (viewer) => setDefaultViewPosition(viewer, "right"));
commands.registerCommand("front", (viewer) => setDefaultViewPosition(viewer, "front"));
commands.registerCommand("back", (viewer) => setDefaultViewPosition(viewer, "back"));
commands.registerCommand("se", (viewer) => setDefaultViewPosition(viewer, "se"));
commands.registerCommand("sw", (viewer) => setDefaultViewPosition(viewer, "sw"));
commands.registerCommand("ne", (viewer) => setDefaultViewPosition(viewer, "ne"));
commands.registerCommand("nw", (viewer) => setDefaultViewPosition(viewer, "nw"));

commands.registerCommandAlias("clearMarkup", "clearOverlay");
commands.registerCommandAlias("clearSelected", "unselect");
commands.registerCommandAlias("getSnapshot", "createPreview");
commands.registerCommandAlias("zoomToExtents", "zoomExtents");

commands.registerCommandAlias("top", "k3DViewTop");
commands.registerCommandAlias("bottom", "k3DViewBottom");
commands.registerCommandAlias("left", "k3DViewLeft");
commands.registerCommandAlias("right", "k3DViewRight");
commands.registerCommandAlias("front", "k3DViewFront");
commands.registerCommandAlias("back", "k3DViewBack");
commands.registerCommandAlias("se", "k3DViewSE");
commands.registerCommandAlias("sw", "k3DViewSW");
commands.registerCommandAlias("ne", "k3DViewNE");
commands.registerCommandAlias("nw", "k3DViewNW");
