using System.Text;

namespace EmailService.Services
{
    public static class TaskService
    {
        public static void CreateThunderbirdTask(string subject, DateTime dtStart, int DureeMinutes)
        {
            var dtEnd = dtStart.AddMinutes(DureeMinutes); 

            string icsContent = $@"
                BEGIN:VCALENDAR
                VERSION:2.0
                PRODID:-//MonApplication//Évènement Thunderbird//FR
                BEGIN:VEVENT
                SUMMARY:{subject}
                DTSTART:{dtStart:yyyyMMddTHHmmssZ}
                DTEND:{dtEnd:yyyyMMddTHHmmssZ}
                PRIORITY:5
                STATUS:CONFIRMED
                END:VEVENT
                END:VCALENDAR
                ";

            string filePath = Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid()}.ics");
            File.WriteAllText(filePath, icsContent, Encoding.UTF8);

            // Ouvre le fichier pour import dans Thunderbird
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo
            {
                FileName = filePath,
                UseShellExecute = true
            });
        }
    }
}
