import type { DataDomain } from './DataDomain.js'

export interface DomainElementSchema {
  /**
   * The kind of the domain element.
   */
  kind: string
  /**
   * The unique key of the domain element.
   */
  key: string
}

export abstract class DomainElement implements DomainElementSchema {
  /**
   * A reference to the root DataDomain instance.
   */
  protected root: DataDomain

  /**
   * The root DataDomain instance.
   */
  get domain(): DataDomain {
    return this.root
  }

  abstract accessor kind: string

  /**
   * The unique key of the domain element.
   * Since keys are immutable, we use a private field to store the key.
   */
  #key: string

  /**
   * The unique key of the domain element.
   */
  get key(): string {
    return this.#key
  }

  /**
   * @param root The root DataDomain instance.
   * @param key The unique key of the domain element.
   */
  constructor(root: DataDomain, key: string) {
    this.root = root
    this.#key = key
  }
}
