/// <summary>
        /// This method parses the <see cref="LocalUserSettings"/> into a string and writes it to disk.
        /// </summary>
        private async Task <string> WriteLocalUserSettingsFile(LocalUserSettings deploymentManifestModel)
        {
            var localUserSettingsFilePath = GetLocalUserSettingsFilePath();
            var settingsFilejsonString    = JsonConvert.SerializeObject(deploymentManifestModel, new JsonSerializerSettings
            {
                Formatting        = Formatting.Indented,
                NullValueHandling = NullValueHandling.Ignore,
                ContractResolver  = new SerializeModelContractResolver()
            });

            await _fileManager.WriteAllTextAsync(localUserSettingsFilePath, settingsFilejsonString);

            return(localUserSettingsFilePath);
        }
        /// <summary>
        /// This method updates the local user settings json file by adding the name of the stack that was most recently used.
        /// If the file does not exists then a new file is generated.
        /// </summary>
        public async Task UpdateLastDeployedStack(string stackName, string projectName, string?awsAccountId, string?awsRegion)
        {
            try
            {
                if (string.IsNullOrEmpty(projectName))
                {
                    throw new FailedToUpdateLocalUserSettingsFileException("The Project Name is not defined.");
                }
                if (string.IsNullOrEmpty(awsAccountId) || string.IsNullOrEmpty(awsRegion))
                {
                    throw new FailedToUpdateLocalUserSettingsFileException("The AWS Account Id or Region is not defined.");
                }

                var localUserSettings = await GetLocalUserSettings();

                var lastDeployedStack = localUserSettings?.LastDeployedStacks?
                                        .FirstOrDefault(x => x.Exists(awsAccountId, awsRegion, projectName));

                if (localUserSettings != null)
                {
                    if (lastDeployedStack != null)
                    {
                        if (lastDeployedStack.Stacks == null)
                        {
                            lastDeployedStack.Stacks = new List <string> {
                                stackName
                            };
                        }
                        else
                        {
                            if (!lastDeployedStack.Stacks.Contains(stackName))
                            {
                                lastDeployedStack.Stacks.Add(stackName);
                            }
                            lastDeployedStack.Stacks.Sort();
                        }
                    }
                    else
                    {
                        localUserSettings.LastDeployedStacks = new List <LastDeployedStack>()
                        {
                            new LastDeployedStack(
                                awsAccountId,
                                awsRegion,
                                projectName,
                                new List <string>()
                            {
                                stackName
                            })
                        };
                    }
                }
                else
                {
                    var lastDeployedStacks = new List <LastDeployedStack> {
                        new LastDeployedStack(
                            awsAccountId,
                            awsRegion,
                            projectName,
                            new List <string>()
                        {
                            stackName
                        })
                    };
                    localUserSettings = new LocalUserSettings(lastDeployedStacks);
                }

                await WriteLocalUserSettingsFile(localUserSettings);
            }
            catch (Exception ex)
            {
                throw new FailedToUpdateLocalUserSettingsFileException($"Failed to update the local user settings file " +
                                                                       $"to include the last deployed to stack '{stackName}'.", ex);
            }
        }