using System;
using System.Collections.Generic;
using System.Text;
using c24.SolutionNormalizer.Entities;

namespace c24.SolutionNormalizer.SolutionProcessing
{
    public class SolutionConfiguration
    {
        /// <summary>
        /// Create the projects related build platform config section of a solution file
        /// </summary>
        /// <param name="projectGuids"></param>
        /// <param name="mappings"></param>
        /// <returns></returns>
        public string CreateProjectsConfigurationPlatforms(IEnumerable<Guid> projectGuids, List<MappingPair> mappings)
        {
            var sb = new StringBuilder();

            //match each (GUID identified) project with each build configuration
            foreach (var projectGuid in projectGuids)
            {
                foreach (var mapping in mappings)
                {
                    var projectFormatedGuid = projectGuid.ToString("B");

                    sb.AppendFormat("\t\t{0}.{1}|Any CPU.ActiveCfg = {2}|Any CPU\r\n", projectFormatedGuid.ToUpper(), mapping.SolutionBuildType, mapping.ProjectBuildType);
                    sb.AppendFormat("\t\t{0}.{1}|Any CPU.Build.0 = {2}|Any CPU\r\n", projectFormatedGuid.ToUpper(), mapping.SolutionBuildType, mapping.ProjectBuildType);
                }
            }

            return sb.ToString();
        }

        /// <summary>
        /// Create the solution build platforms config section
        /// </summary>
        /// <returns></returns>
        public string CreateSolutionConfigurationPlatforms(List<MappingPair> mappings)
        {
            var sb = new StringBuilder();

            foreach (var mapping in mappings)
            {
                sb.AppendFormat("\t\t{0}|Any CPU = {1}|Any CPU\r\n", mapping.SolutionBuildType, mapping.SolutionBuildType);
            }

            return sb.ToString();
        }
    }
}