using System;
using System.Web;
using System.Xml.Linq;

namespace Azyobuzi.Twirunrun
{
    public class SourceClient
    {
        public SourceClient() { }
        public SourceClient(string sourcestr)
        {
            if (sourcestr == "web" || sourcestr == "Keitai Mail")
            {
                Name = sourcestr;
                LinkTo = "http://twitter.com/";
            }
            else
            {
                var xe = XElement.Parse(sourcestr.Replace("&", "&amp;"));
                Name = xe.Value;
                LinkTo = xe.Attribute("href").Value;
            }
        }

        public string Name { set; get; }
        public string LinkTo { set; get; }

        public override string ToString()
        {
            return string.Format(@"<a href=""{0}"" rel=""nofollow"">{1}</a>",
                LinkTo.HtmlAttributeEncode(), Name.HtmlEncode());
        }
    }
}
