package com.madstripesdk;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableMap;
import com.stripe.stripeterminal.external.models.ReaderSoftwareUpdate;

class NativeReaderSoftwareUpdate {

  private String estimatedUpdateTimeString;
  private int estimatedUpdateTime;
  private String deviceSoftwareVersion;
  private String components;
  private int requiredAt;

  public NativeReaderSoftwareUpdate(ReaderSoftwareUpdate update) {
    this.estimatedUpdateTimeString = update.getTimeEstimate().getDescription();
    int estimate = 0;
    switch (update.getTimeEstimate()) {
      case LESS_THAN_ONE_MINUTE:
        break;
      case ONE_TO_TWO_MINUTES:
        estimate = 1;
        break;
      case TWO_TO_FIVE_MINUTES:
        estimate = 2;
        break;
      case FIVE_TO_FIFTEEN_MINUTES:
        estimate = 3;
        break;
    }
    this.estimatedUpdateTime = estimate;

    this.deviceSoftwareVersion = update.getVersion();

    /*
            INCREMENTAL,

        FIRMWARE,

        CONFIG,

        KEYS;
     */
    // this.components = todo

    this.requiredAt = (int) update.getRequiredAt().getTime();
  }

  public String getEstimatedUpdateTimeString() {
    return estimatedUpdateTimeString;
  }

  public void setEstimatedUpdateTimeString(String estimatedUpdateTimeString) {
    this.estimatedUpdateTimeString = estimatedUpdateTimeString;
  }

  public int getEstimatedUpdateTime() {
    return estimatedUpdateTime;
  }

  public void setEstimatedUpdateTime(int estimatedUpdateTime) {
    this.estimatedUpdateTime = estimatedUpdateTime;
  }

  public String getDeviceSoftwareVersion() {
    return deviceSoftwareVersion;
  }

  public void setDeviceSoftwareVersion(String deviceSoftwareVersion) {
    this.deviceSoftwareVersion = deviceSoftwareVersion;
  }

  public String getComponents() {
    return components;
  }

  public void setComponents(String components) {
    this.components = components;
  }

  public int getRequiredAt() {
    return requiredAt;
  }

  public void setRequiredAt(int requiredAt) {
    this.requiredAt = requiredAt;
  }

  public ReadableMap map() {
    final WritableMap map = Arguments.createMap();
    map.putString("estimatedUpdateTimeString", estimatedUpdateTimeString);
    map.putInt("estimatedUpdateTime", estimatedUpdateTime);
    map.putString("deviceSoftwareVersion", deviceSoftwareVersion);
    // components
    map.putInt("requiredAt", requiredAt);
    return map;
  }

}
