using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FWHandler
{
    public class HTMLProvider : IHTML
    {
        private StringBuilder HTMLHead = new StringBuilder();
        private StringBuilder HTMLBody = new StringBuilder();
        private StringBuilder HTMLBody_Table2_td = new StringBuilder();
        private StringBuilder HTMLbody_Table2_tr = new StringBuilder();
        private StringBuilder HTMLTail = new StringBuilder();
        public StringBuilder InjectHTML_Head()
        {
            HTMLHead.Clear();
            HTMLHead.Append("<!DOCTYPE html><html><head>" +
                            "<style>" +
                            "td {border: 1px solid #ddd;border-collapse: collapse;border-spacing:0px;padding-left:5px;padding-right:5px;padding-top:1px;padding-bottom:1px;font-size:11pt;} "+
                            "</style>" +
                            "</head>");            
            return HTMLHead;
        }
    
        public StringBuilder InjectHTML_Body_Table1(string Date, string Project, string BuildInfo, string Requestor, string Duration, int passed, int failed, string ArrowStatus)
        {
            if(ArrowStatus == "pass")
            {
                ArrowStatus = "<SPAN style=\"FONT-SIZE: 200%; FONT-FAMILY: Wingdings; COLOR:green\">&#233;</SPAN>";
            }
            else
            {
                ArrowStatus = "<SPAN style=\"FONT-SIZE: 200%; FONT-FAMILY: Wingdings; COLOR:red\">&#234;</SPAN>";
            }
            HTMLBody.Clear();
            HTMLBody.Append($"<body><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">" +
                            $"<tr bgcolor=#f1f1f1><td><font size=\"4\"><b>Start date:</b></font></td>" +
                            $"<td >{Date}</td></tr>" +
                            $"<tr bgcolor=#f1f1f1><td><font size=\"4\"><b>Project:</b></font></td>" +
                            $"<td >{Project}</td></tr>" +
                            $"<tr bgcolor=#f1f1f1><td><font size=\"4\"><b>Build info:</b></font></td>" +
                            $"<td>{BuildInfo}</td></tr>" +
                            $"<tr bgcolor=#f1f1f1><td><font size=\"4\"><b>Requested by:</b></font></td>" +
                            $"<td>{Requestor}</td></tr>" +
                            $"<tr bgcolor=#f1f1f1><td><font size=\"4\"><b>Total run time:</b></font></td>" +
                            $"<td>{Duration}</td></tr>" +
                            $"<tr bgcolor=#f1f1f1><td><font size=\"4\"><b>Overall test result:</b></font></td>" +
                            $"<td> Passed:<font color=\"green\"><b>{passed}</b></font> <br> Failed:<font color=\"red\"><b>{failed}</b></font></td></tr>" +
                            $"<tr bgcolor=#f1f1f1><td><font size=\"4\"><b>Test status:</b></font></td>" +
                            $"<td align=center><p style=\"margin: 5px 0px 0px 0px\">{ArrowStatus}</p></td></tr></table>" +
                            $"<br><br>");
            return HTMLBody;
        }

        public StringBuilder InjectHTML_Body_Table2_Td()
        {
            HTMLBody_Table2_td.Clear();
            HTMLBody_Table2_td.Append($"<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">" +
                $"<tr bgcolor=#1C6EA4 height=\"40px\">" +
                $"<td align=center><font color=\"white\"><b>Test Case</b></font></td>" +
                $"<td align=center><font color=\"white\"><b>Status</b></font></td>" +
                $"<td align=center><font color=\"white\"><b>Duration</b></font></td>" +
                $"<td align=center><font color=\"white\"><b>Error</b></font></td>" +
                $"<td align=center width=\"35%\"><font color=\"white\"><b>Error Message</b></td></font>" +
                $"</tr>");
            return HTMLBody_Table2_td;
        }

        public StringBuilder InjectHTML_Body_Table2_Tr(string TCName, string Status, string Duration, string Error, string ErrorMesage, string pathToErrorPicture)
        {
            string imgFinal = string.Empty;
            if(Status == "failed" && pathToErrorPicture != "")
            {
                imgFinal = string.Format("<a href=\"{0}\"><center><img src=\"{0}\" width=\"175\"></a></center>", pathToErrorPicture);
            }
            else
            {
                imgFinal = "";
            }
            HTMLbody_Table2_tr.Clear();
            HTMLbody_Table2_tr.Append("<tr>" +
                                      $"<td>{TCName}</td>" +
                                      $"<td>{Status}</td>" +
                                      $"<td>{Duration}</td>" +
                                      $"<td>{Error}</td>" +
                                      $"<td>{imgFinal}<br>{ErrorMesage}</td>" +
                                      "</tr>");
            return HTMLbody_Table2_tr;
        }
        public StringBuilder InjectHTML_Tail()
        {
            HTMLTail.Clear();
            HTMLTail.Append("</table></body></html>");
            return HTMLTail;
        }
    }
}
