import { RTEBlock } from '../../components/vega-rich-text-editor/dto/blocks/block.abstract';
import { RTENode } from '../../components/vega-rich-text-editor/dto/nodes/node.abstract';
/**
 * RTEDTOClassManager is a singleton class that manages the registration and retrieval of RTE DTO classes.
 * It allows for the dynamic handling of different RTE blocks and nodes by their types.
 */
class RTEDTOClassManager {
  constructor() {
    // Register RTE Block DTO classes.
    this.RTE_BLOCK_DTO_CLASS_MAP = new Map();
    // Register RTE Block DTO classes.
    this.RTE_NODE_DTO_CLASS_MAP = new Map();
  }
  /**
   * Registers a new RTE DTO class.
   *
   * @typedef T - The type of the RTE DTO class to register.
   * @param {string} type - The type identifier for the RTE DTO class.
   * @param {ClassType<T>} RTEDTOClass - The class constructor for the RTE DTO.
   */
  registerRTEDTOClass(type, RTEDTOClass) {
    if (RTEDTOClass.prototype instanceof RTEBlock) {
      this.RTE_BLOCK_DTO_CLASS_MAP.set(type, RTEDTOClass);
    }
    else if (RTEDTOClass.prototype instanceof RTENode) {
      this.RTE_NODE_DTO_CLASS_MAP.set(type, RTEDTOClass);
    }
    else {
      throw new Error(`Invalid RTE DTO class type: ${type}`);
    }
  }
  /**
   * Retrieves the RTE block class for a given type.
   *
   * @param {string} type - The type identifier for the RTE block.
   * @returns {Nullable<RTEBlockDTOClass>} - The class constructor for the RTE block, or null if not found.
   */
  getRTEBlockClass(type) {
    return this.RTE_BLOCK_DTO_CLASS_MAP.get(type);
  }
  /**
   * Retrieves the RTE node class for a given type.
   *
   * @param {string} type - The type identifier for the RTE node.
   * @returns {Nullable<RTENodeDTOClass>} - The class constructor for the RTE node, or null if not found.
   */
  getRTENodeClass(type) {
    return this.RTE_NODE_DTO_CLASS_MAP.get(type);
  }
}
export default new RTEDTOClassManager();
