private PlexSsoConfig LoadConfig(string configFile, IConfiguration configuration)
        {
            var serialiserConfig = new JsonSerializerOptions
            {
                AllowTrailingCommas = true,
                Converters          =
                {
                    new JsonStringEnumConverter()
                },
                PropertyNamingPolicy        = JsonNamingPolicy.CamelCase,
                PropertyNameCaseInsensitive = true,
                WriteIndented = true
            };

            PlexSsoConfig plexSsoConfig;

            if (File.Exists(configFile))
            {
                plexSsoConfig = JsonSerializer.Deserialize <PlexSsoConfig>(File.ReadAllText(configFile), serialiserConfig);
                UpdateConfigWithCliOptions(ref plexSsoConfig, configuration);
            }
            else
            {
                plexSsoConfig = new PlexSsoConfig();
                UpdateConfigWithCliOptions(ref plexSsoConfig, configuration);
                File.WriteAllText(configFile, JsonSerializer.Serialize <PlexSsoConfig>(plexSsoConfig, serialiserConfig));
            }

            return(plexSsoConfig);
        }
        public ConfigurationService(IConfiguration configuration)
        {
            _configDirectory = configuration[ConfigurationDirectoryKey] ?? Environment.CurrentDirectory;
            var configFile = Path.Join(_configDirectory, ConfigurationFileName);

            _config = LoadConfig(configFile, configuration);
        }
        private void UpdateConfigWithCliOptions(ref PlexSsoConfig plexSsoConfig, IConfiguration configuration)
        {
            string server, preferences, cookieDomain;

            if ((server = configuration[ServerConfigurationKey]) != null)
            {
                plexSsoConfig.ServerIdentifier = server;
            }
            if ((preferences = configuration[PreferencesConfigurationKey]) != null)
            {
                plexSsoConfig.PlexPreferencesFile = preferences;
            }
            if ((cookieDomain = configuration[CookieDomainConfigurationKey]) != null)
            {
                plexSsoConfig.CookieDomain = cookieDomain;
            }
        }