using EFlib;
using Model;
using System.Collections.Immutable;
using System.Reflection.PortableExecutable;

namespace EFMapping
{
    public static class EFChampionMapper
    {

        public static EFChampion toEF(this Champion Champ, SQLiteContext context)
        {

            EFChampion? EfChampion = context.Champions.Find(Champ.Name);
            if (EfChampion == null)
            {
                EfChampion = new()
                {
                    Name = Champ.Name,
                    Bio = Champ.Bio,
                    Icon = Champ.Icon,
                    Class = Champ.Class,
                    Image = new() { Id = Guid.NewGuid(), Base64 = Champ.Image.Base64 },


                };
                EfChampion.Skills = Champ.Skills.Select(skill => skill.toEF(EfChampion, context)).ToList();
                EfChampion.Characteristics = Champ.Characteristics.Select(Charac => Charac.toEF(EfChampion, context)).ToList();
            }
            return EfChampion;

        }

        public static Champion toModel(this EFChampion EFChamp)
        {
            var champion = new Champion(EFChamp.Name, EFChamp.Class, EFChamp.Icon, EFChamp.Image.Base64, EFChamp.Bio);
            if (EFChamp.Skills != null) foreach (var skill in EFChamp.Skills) { champion.AddSkill(skill.toModel()); }
            if (EFChamp.Characteristics != null) foreach (var charac in EFChamp.Characteristics) { champion.AddCharacteristics(charac.toModel()); }
            return champion;
        }
    }
}