import BaseEntity from "./BaseEntity";
import { StringKeyValueEntity } from "./StringKeyValueEntity";

export class PollingEntity extends BaseEntity {
  name: string = "";
  group_uuid = "";
  polling_signal_sources: StringKeyValueEntity[] = [];
  note: string = "";

  public static copy(dest: PollingEntity, src?: PollingEntity) {
    if (!src) {
      src = new PollingEntity();
    }

    dest.uuid = src.uuid;
    dest.base_note = src.base_note;
    dest.name = src.name;
    dest.polling_signal_sources = src.polling_signal_sources;
    dest.group_uuid = src.group_uuid;
    dest.note = src.note;
  }
}

export class PollingGroupEntity extends BaseEntity {
  parent_uuid: string = "";
  name: string = "";
}

export class PollingTreeItemEntity {
  uuid = "";
  parent = "";
  name = "";
  is_group = false;
  children: PollingTreeItemEntity[] = [];
  item_data: PollingEntity | null = null;

  constructor(
    uuid?: string,
    parent?: string,
    name?: string,
    is_group?: boolean,
    item_data?: any,
    children?: PollingTreeItemEntity[]
  ) {
    this.uuid = uuid ?? "";
    this.parent = parent ?? "";
    this.name = name ?? "";
    this.is_group = is_group ?? false;
    this.children = children ?? (Array.isArray(children) ? children : []);
    this.item_data = item_data;
  }
}
