import  { SimConnectConstants } from 'node-simconnect';

export class DataDefiniion {
  private definitions: Array<any> = [];
  private id: number;
  private requestId: number;
  private period: number;
  private handler: Function;

  constructor(id, requestId, period, handler) {
    this.id = id;
    this.requestId = requestId;
    this.handler = handler;
    this.period = period;
  }

  add(definition :Array<any>): void {
    this.definitions.push(definition);
  }

  build(handle, requestsMap: Map<number, Function>) {
    this.definitions.forEach(definition => {
      handle.addToDataDefinition(this.id, ...definition);
    });
    requestsMap.set(this.requestId, this.handler);
    handle.requestDataOnSimObject(this.requestId, this.id, SimConnectConstants.OBJECT_ID_USER, this.period);
  }

}