import { nonNullable } from "@likec4/core";
import { DefaultNameProvider, isNamed } from "langium";
import { ast } from "../ast.js";
export class LikeC4NameProvider extends DefaultNameProvider {
  constructor(services) {
    super();
    this.services = services;
  }
  getNameStrict(node) {
    return nonNullable(
      this.getName(node),
      `Failed getName for ${this.services.workspace.AstNodeLocator.getAstNodePath(node)}`
    );
  }
  getName(node) {
    if (isNamed(node)) {
      return node.name;
    }
    if (ast.isDeployedInstance(node)) {
      return node.element.el.$refText;
    }
    return void 0;
  }
  getNameNode(node) {
    if (isNamed(node)) {
      return super.getNameNode(node);
    }
    if (ast.isDeployedInstance(node)) {
      return node.element.el.$refNode;
    }
    return void 0;
  }
}
