// Copyright (C) 2023 WYATT GROUP
// Please see the AUTHORS file for details.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

enum DevMode {
  /// Mocked values
  mock,

  /// Real values from REST API
  rest,

  /// Emulated values with Firebase Emulator
  emulator,

  /// Real values from Firebase
  real;

  @override
  String toString() => name;

  /// Tries to parse String and returns mode. Fallback is returned if there
  /// is an error during parsing.
  static DevMode fromString(String? mode, {DevMode fallback = DevMode.mock}) {
    for (final m in values) {
      if (m.name == mode) {
        return m;
      }
    }

    return fallback;
  }
}
