import 'dart:convert';
import 'dart:io';
import 'dart:ui';

import 'package:pshared/config/common.dart';


class Constants extends CommonConstants {
  static const String _clientIdMobile = 'net.sendico.mobile-9c7e7c4b-6f1a-4b8e-9a2d-3e5f0c1a7d92';

  static Locale get defaultLocale => CommonConstants.defaultLocale;
  static String get clientId => _clientIdMobile;
  static String get accessTokenStorageKey => CommonConstants.accessTokenStorageKey;
  static String get refreshTokenStorageKey => CommonConstants.refreshTokenStorageKey;
  static String get currentOrgKey => CommonConstants.currentOrgKey;
  static String get apiUrl => CommonConstants.apiUrl;
  static String get serviceUrl => CommonConstants.serviceUrl;
  static String get posthogApiKey => CommonConstants.posthogApiKey;
  static String get posthogHost => CommonConstants.posthogHost;
  static int get defaultDimensionLength => CommonConstants.defaultDimensionLength;
  static String get deviceIdStorageKey => CommonConstants.deviceIdStorageKey;
  static String get nilObjectRef => CommonConstants.nilObjectRef;
  static Color get themeColor => CommonConstants.themeColor;

  static Future<void> initialize() async {
    var configFile = File('./config/config.json');
    if (await configFile.exists()) {
      var configJson = jsonDecode(await configFile.readAsString());
      CommonConstants.applyConfiguration({
        ...configJson,
        'clientId': configJson['clientId'] ?? _clientIdMobile, 
      });
    } else {
      CommonConstants.clientId = _clientIdMobile; 
    }
  }
}
