/// The one file that differs per client.
///
/// Everything else in this shell is identical across every installation; a new
/// client is this file, a Firebase project and an icon set.
class Instance {
  /// Passed at build time so a misconfigured build fails loudly rather than
  /// silently pointing at someone else's academy:
  ///
  ///   flutter build appbundle --dart-define=BASE_URL=https://client.example.com
  static const String baseUrl = String.fromEnvironment(
    'BASE_URL',
    defaultValue: '',
  );

  static const String appName = String.fromEnvironment(
    'APP_NAME',
    defaultValue: 'El Captain',
  );

  static Uri get portal => Uri.parse('$baseUrl/app');

  static Uri get sessionExchange => Uri.parse('$baseUrl/app/session-exchange');

  static Uri get tokenEndpoint => Uri.parse('$baseUrl/app/native/token');

  static Uri get revokeEndpoint => Uri.parse('$baseUrl/app/native/revoke');

  static Uri get pushTokenEndpoint => Uri.parse('$baseUrl/app/push/token');

  /// The only host this shell will ever render.
  ///
  /// Checked in the navigation delegate against the origin read natively from
  /// the controller — never from anything the page says about itself. A link
  /// to anywhere else opens in the system browser, where it belongs and where
  /// it cannot reach the WebView's cookies or its bridges.
  static String get allowedHost => Uri.parse(baseUrl).host;

  static bool get isConfigured => baseUrl.isNotEmpty && allowedHost.isNotEmpty;
}
