using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.Metrics;
using System.Xml.Serialization;

namespace ModernLangToolsApp;

public class Program
{
    private static void MessageReceived(string message)
    {
        Console.WriteLine(message);
    }
    public static void Main(string[] args)
    {
        Task2();
        Task3();

        JediDelegateTest();
        JediLambdaTest();

        TestPerson();
    }

    [Description("Task2")]
    public static void Task2() {
        Jedi j1 = new Jedi
        {
            Name = "Obi-Wan",
            MidiChlorianCount = 15000
        };

        //Kimentés
        var serializer = new XmlSerializer(typeof(Jedi));
        var stream = new FileStream("jedi.txt", FileMode.Create);
        serializer.Serialize(stream, j1);
        stream.Close();

        //Test
        /*Process.Start(new ProcessStartInfo
        {
            FileName = "jedi.txt",
            UseShellExecute = true,
        });*/

        //Visszaolvasás
        var serializer2 = new XmlSerializer(typeof(Jedi));
        var stream2 = new FileStream("jedi.txt", FileMode.Open);

        var clone = (Jedi)serializer2.Deserialize(stream2);
        stream.Close();
    }

    [Description("Task3")]
    public static void Task3()
    {
        Jedi j1 = new Jedi
        {
            Name = "Obi-Wan",
            MidiChlorianCount = 15000
        };

        var council = new JediCouncil();

        council.CouncilChanged += MessageReceived;

        council.Add(new Jedi { Name = "Luke", MidiChlorianCount = 20000 });
        council.Add(j1);

        council.Remove();
        council.Remove();

        
    }

    [Description("Task4")]
    public static void JediDelegateTest()
    {
        var council = new JediCouncil();
        council.Add(new Jedi { Name = "Luke", MidiChlorianCount = 20000 });
        council.Add(new Jedi { Name = "Anakin", MidiChlorianCount = 500 });
        council.Add(new Jedi { Name = "Anakin2", MidiChlorianCount = 500 });


        var lowMidiJedis = council.GetLowMidiCount_Delegate();
        foreach (var j in lowMidiJedis)
        {
            Console.WriteLine(j.Name);
        }
    }

    [Description("Task5")]
    public static void JediLambdaTest()
    {
        var council = new JediCouncil();
        council.Add(new Jedi { Name = "Luke", MidiChlorianCount = 20000 });
        council.Add(new Jedi { Name = "Anakin", MidiChlorianCount = 500 });
        council.Add(new Jedi { Name = "Anakin2", MidiChlorianCount = 500 });

        var lowMidiJedis = council.GetLowMidiCount_Lambda();
        foreach (var j in lowMidiJedis)
        {
            Console.WriteLine(j.Name);
        }
    }

    [Description("Task6")]
    static void TestPerson()
    {
        var employees = new Person[] { new Person("Joe", 20), new Person("Jill", 30) };

        ReportPrinter reportPrinter = new ReportPrinter(
            employees,
            () => Console.WriteLine("Employees"),
            () => Console.WriteLine("Number of Employees: " + employees.Length),
            (Person person) => {Console.WriteLine($" Name: {person.Name} (Age: {person.Age})");}
            );

        reportPrinter.PrintReport();
    }
}
