export class Element {
  private _name = '';
  protected parent_name: string;

  public get full_name (): string {
    if (this.parent_name)
      return `${this.parent_name}_${this.name}`;
    return this.name;
  }

  public get name (): string {
    return this._name;
  }

  public set name (val: string) {
    const new_name = val.replace (/[^a-z0-9]/giu, '')
      .replace (/^[0-9]+/iu, '');
    if (new_name === '')
      throw new Error (`invalid node name ${val}`);
    this._name = new_name;
  }

  public get parent (): string {
    return this.parent_name;
  }

  public constructor (name: string, parent = '') {
    this.name = name;
    this.parent_name = parent;
  }

  // eslint-disable-next-line @typescript-eslint/naming-convention
  public toString (): string {
    return this.full_name;
  }
}