package com.oguerreiro.resilient.domain.enumeration;

import java.math.BigDecimal;

/**
 * Unit Variable Type
 * The type of data this unit represents
 */
public enum UnitValueType {
  /**
   * String value
   */
  STRING,
  /**
   * Decimal value
   */
  DECIMAL,
  /**
   * boolean value
   */
  BOOLEAN;

  public boolean isValueValid(String value) {
    try {
      switch (this) {
      case STRING: {
        String.valueOf(value);
        break;
      }
      case BOOLEAN: {
        Boolean.valueOf(value);
        break;
      }
      case DECIMAL: {
        new BigDecimal(value);
        break;
      }
      default: {
        // Unexpected UnitValueType
        return false;
      }
      }
    } catch (Exception ex) {
      return false;
    }

    return true;
  }
}
