import 'moment';
import { checkStringOrDate, isDef } from './util.js';

/*
 * Philip Crotwell
 * University of South Carolina, 2019
 * http://www.seis.sc.edu
 */
// StationXML classes
class Network {
  constructor(networkCode) {
    this.networkCode = networkCode;
    this.stations = [];
  }

  get startDate() {
    return this._startDate;
  }

  set startDate(value) {
    this._startDate = checkStringOrDate(value);
  }

  get endDate() {
    return this._endDate;
  }

  set endDate(value) {
    this._endDate = checkStringOrDate(value);
  }

  codes() {
    return this.networkCode;
  }

  isTempNet() {
    const first = this.networkCode.charAt(0);
    return first === 'X' || first === 'Y' || first === 'Z' || first >= '0' && first <= '9';
  }

}
class Station {
  /** @private */

  /** @private */
  constructor(network, stationCode) {
    this.network = network;
    this.stationCode = stationCode;
    this.channels = [];
  }

  get startDate() {
    return this._startDate;
  }

  set startDate(value) {
    this._startDate = checkStringOrDate(value);
  }

  get endDate() {
    return this._endDate;
  }

  set endDate(value) {
    this._endDate = checkStringOrDate(value);
  }

  codes() {
    return this.network.codes() + "." + this.stationCode;
  }

}
class Channel {
  /** @private */

  /** @private */

  /** @private */
  constructor(station, channelCode, locationCode) {
    this.station = station;

    if (channelCode.length !== 3) {
      throw new Error("Channel code must be 3 chars: ".concat(channelCode));
    }

    this.channelCode = channelCode;
    this.locationCode = locationCode;

    if (!locationCode) {
      // make sure "null" is encoded as empty string
      this.locationCode = '';
    }

    if (!(this.locationCode.length === 2 || this.locationCode.length === 0)) {
      throw new Error("locationCode must be 2 chars, or empty: \"".concat(locationCode, "\""));
    }
  }

  get startDate() {
    return this._startDate;
  }

  set startDate(value) {
    this._startDate = checkStringOrDate(value);
  }

  get endDate() {
    return this._endDate;
  }

  set endDate(value) {
    this._endDate = checkStringOrDate(value);
  }

  get locationCode() {
    return this._locationCode;
  }

  set locationCode(value) {
    this._locationCode = value;

    if (!value) {
      // make sure "null" is encoded as empty string
      this._locationCode = '';
    }
  }
  /**
   * Checks if this channel has sensitivity defined, within the response.
   * @return {Boolean}         true if instrumentSensitivity exits
   */


  hasInstrumentSensitivity() {
    return isDef(this.response) && isDef(this.response.instrumentSensitivity);
  }

  set instrumentSensitivity(value) {
    if (typeof this.response === 'undefined') {
      this.response = new Response(value);
    } else {
      this.response.instrumentSensitivity = value;
    }

    return this;
  }

  get instrumentSensitivity() {
    if (this.response) {
      return this.response.instrumentSensitivity;
    } else {
      throw new Error("no Response or InstrumentSensitivity defined");
    }
  }

  codes() {
    return this.station.codes() + "." + this.locationCode + "." + this.channelCode;
  }

}
class InstrumentSensitivity {
  constructor(sensitivity, frequency, inputUnits, outputUnits) {
    this.sensitivity = sensitivity;
    this.frequency = frequency;
    this.inputUnits = inputUnits;
    this.outputUnits = outputUnits;
  }

}
class Response {
  constructor(instrumentSensitivity, stages) {
    if (instrumentSensitivity) {
      this.instrumentSensitivity = instrumentSensitivity;
    }

    if (stages) {
      this.stages = stages;
    }
  }

}
class Stage {
  constructor(filter, decimation, gain) {
    this.filter = filter;
    this.decimation = decimation;
    this.gain = gain;
  }

}
class AbstractFilterType {
  constructor(inputUnits, outputUnits) {
    this.inputUnits = inputUnits;
    this.outputUnits = outputUnits;
  }

}
class PolesZeros extends AbstractFilterType {
  constructor(inputUnits, outputUnits) {
    super(inputUnits, outputUnits);
  }

}
class FIR extends AbstractFilterType {
  constructor(inputUnits, outputUnits) {
    super(inputUnits, outputUnits);
  }

}
class CoefficientsFilter extends AbstractFilterType {
  constructor(inputUnits, outputUnits) {
    super(inputUnits, outputUnits);
  }

}
class Decimation {}
class Gain {}
/**
 * Extract all stations from all networks in the input array.
 * @param   networks Array of networks.
 * @return           Array of stations.
 */

function extractAllStations(networks) {
  let out = [];

  for (let n of networks) {
    out = out.concat(n.stations);
  }

  return out;
}
/**
 * Extract all channels from all stations from all networks in the input array.
 * @param   networks Array of networks.
 * @return           Array of channels.
 */

function extractAllChannels(networks) {
  let out = [];

  for (let n of networks) {
    for (let s of n.stations) {
      out = out.concat(s.channels);
    }
  }

  return out;
}

export { AbstractFilterType, Channel, CoefficientsFilter, Decimation, FIR, Gain, InstrumentSensitivity, Network, PolesZeros, Response, Stage, Station, extractAllChannels, extractAllStations };
//# sourceMappingURL=stationxml.js.map
