using System;
using System.Net;

namespace Katteker.Changelog
{
    public static class ChangelogExtension
    {
        /// <summary>
        /// Format the Changelog as Html compliant file.
        /// </summary>
        public static string AsHtml(this ChangelogFile value)
        {
            string result;
            switch (value.ChangelogFileType)
            {
                case ChangelogFileType.TextFile:
                    var plainText = WebUtility.HtmlEncode(value.Content);
                    result = plainText?.Replace(Environment.NewLine, "<br />");
                    break;
                case ChangelogFileType.MarkdownFile:
                    result = new MarkdownSharp.Markdown().Transform(value.Content);
                    break;
                default:
                    result = value.Content;
                    break;
            }

            return result;
        }

    }
}
