using OpenQA.Selenium.Edge;
using OpenQA.Selenium;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
using Domino;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;

namespace Hochbaustatistik.Utilities
{
    internal static class VariousHelper
    {
        [ExcludeFromCodeCoverage]
        private static bool SendEmail(string attachment)
        {
            try
            {
                NotesSession nSession = new NotesSession();
                nSession.Initialize("Mk130881");

                NotesDatabase nDatabase = nSession.GetDatabase("DOMMAIL4/SRV/Stadt Dortmund/DE", "MAIL\\mkoebis-riedel");

                NotesDocument nDocument = nDatabase.CreateDocument();

                //Attachment
                var richTextItem = nDocument.CreateRichTextItem("files");
                richTextItem.EmbedObject(EMBED_TYPE.EMBED_ATTACHMENT, "", attachment, "attachment");


                string[] recipients = { "mkoebis-riedel@stadtdo.de, katyes@gmx.li" };

                string txtMessage = "Sehr geehrte Damen und Herren,\r\n\r\nanbei erhalten Sie die Auswertung zur Hochbaustatistik für das Jahr " + DateTime.Today.Year + ".\r\n\r\nBitte senden Sie jene ausgefüllt zurück an: mkoebis-riedel@stadtdo.de\r\n\r\nDanke und freundliche Grüße";
                nDocument.ReplaceItemValue("Form", "Memo");
                nDocument.ReplaceItemValue("SentTo", recipients);
                nDocument.ReplaceItemValue("Subject", "Hochbaustatistik Auswertung IT.NRW");
                nDocument.ReplaceItemValue("Body", txtMessage); //set body text

                nDocument.SaveMessageOnSend = true;
                nDocument.Send(false, recipients);
                return true;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                return false;
            }
        }

        [ExcludeFromCodeCoverage]
        internal static void DownloadList(string idevUrl)
        {          
            //User: 0521442179
            //Passwort: #Dortmund2022
            IWebDriver driver = new EdgeDriver();

            string loginUrl = idevUrl;

            driver.Navigate().GoToUrl(loginUrl);

            IWebElement site = driver.FindElement(By.Id("05"));
            site.Click();

            site = driver.FindElement(By.Id("loginid"));
            site.SendKeys("0521442179");

            site = driver.FindElement(By.Id("password"));
            site.SendKeys("#Dortmund2022");

            site = driver.FindElement(By.Id("login"));
            site.Click();

            site = driver.FindElement(By.Id("menu100"));
            site.Click();

            site = driver.FindElement(By.LinkText("Bauüberhangsliste"));

            site.Click();

            Thread.Sleep(1000);
            driver.Quit();
        }
    }
}
