const Measurement = require('./Measurement');

class MeasurementBuilder {
  constructor() {
    this.type = null;
    this.variant = null;
    this.position = null;
    this.distance = null;
    this.windowSize = 10; // Default window size
  }

  // e.g. 'pressure', 'flow', etc.
  setType(type) {
    this.type = type;
    return this;
  }

  // e.g. 'predicted' or 'measured', etc..
  setVariant(variant) {
    this.variant = variant;
    return this;
  }

  // Downstream or upstream of parent object
  setPosition(position) {
    this.position = position;
    return this;
  }

  // default size of the data that gets tracked
  setWindowSize(windowSize) {
    this.windowSize = windowSize;
    return this;
  }

  setDistance(distance) {
    this.distance = distance;
    return this;
  }

  build() {
    // Validate required fields
    if (!this.type) {
      throw new Error('Measurement type is required');
    }
    if (!this.variant) {
      throw new Error('Measurement variant is required');
    }
    if (!this.position) {
      throw new Error('Measurement position is required');
    }
    // distance is not a requirement as it can be derived from position

    return new Measurement(
      this.type,
      this.variant,
      this.position,
      this.windowSize,
      this.distance
    );

    
  }
}

module.exports = MeasurementBuilder;
