//using Modules.Library.Application.Gateways;
//using Modules.Library.Application.Models;

//namespace Modules.Library.Application.Queries.Converters;

//internal class CommonPropertiesConverter(ILanguageGateway languageGateway, IGenreGateway genreGateway)
//{
//    /*
//    internal async Task<CommonPropertiesBuilder> GetBuilder(CommonProperties commonProperties)
//    {
//        var commonPropertiesBuilder = new CommonPropertiesBuilder();
//        foreach (var name in commonProperties.Names)
//        {
//            commonPropertiesBuilder.AddName(await languageRepository.GetLanguageById(name.LanguageId),
//                (Domain.Entities.MediaContent.CommonProperties.NameType)name.Type, name.Value);
//        }

//        if (commonProperties.Preview != null) commonPropertiesBuilder.SetPreview(commonProperties.Preview.Url,
//            (Domain.Entities.MediaInfoType)commonProperties.Preview.Type);

//        foreach (var description in commonProperties.Descriptions)
//        {
//            commonPropertiesBuilder.AddDescription(await languageRepository.GetLanguageById(description.LanguageId), description.IsOriginal, description.Value);
//        }

//        foreach (var genre in commonProperties.Genres)
//        {
//            commonPropertiesBuilder.AddGenreProportion(await genreGateway.GetGenreById(genre.GenreId), genre.Proportion);
//        }

//        foreach (var relatedContent in commonProperties.RelatedContent)
//        {
//            commonPropertiesBuilder.AddRelatedContent(relatedContent.Url, (Domain.Entities.MediaInfoType)relatedContent.Type);
//        }

//        commonPropertiesBuilder.SetAnouncementDate(commonProperties.AnnouncementDate);
//        commonPropertiesBuilder.SetEstimatedReleaseDate(commonProperties.EstimatedReleaseDate);
//        commonPropertiesBuilder.SetReleaseDate(commonProperties.ReleaseDate);

//        return commonPropertiesBuilder;
//    }
//    */
//    internal async Task<CommonProperties> Convert(CommonProperties commonProperties)
//    {
//        var commonPropertiesLanguageIds = commonProperties.Names.Select(q => q.LanguageId).ToList();
//        commonPropertiesLanguageIds.AddRange(commonProperties.Descriptions.Select(q => q.LanguageId));

//        var languages = await languageGateway.GetLanguages(q => commonPropertiesLanguageIds.Distinct().Contains(q.Id));
//        var genres = await genreGateway.GetWhere(q => commonProperties.Genres.Select(q => q.Id).Distinct().Contains(q.Id));

//        return new Domain.Models.CommonProperties
//        {
//            Names = commonProperties.Names.Select(q => new Domain.Models.NameItem
//            {
//                Language = Convert(languages.First(x => x.Id == q.LanguageId)),
//                Type = (Domain.Entities.MediaContent.CommonProperties.NameType)q.Type,
//                Value = q.Value,
//            }),
//            Preview = commonProperties.Preview == null ? null : new Domain.Models.MediaInfo
//            {
//                Url = commonProperties.Preview.Url,
//                Type = (Domain.Entities.MediaInfoType)commonProperties.Preview.Type,
//            },
//            Descriptions = commonProperties.Descriptions.Select(q => new Domain.Models.Description
//            {
//                Language = Convert(languages.First(x => x.Id == q.LanguageId)),
//                IsOriginal = q.IsOriginal,
//                Value = q.Value,
//            }),
//            Genres = commonProperties.Genres.Select(q => new Domain.Models.GenreProportion
//            {
//                Genre = Convert(genres.First(x => x.Id == q.GenreId)),
//                Proportion = q.Proportion,
//            }),
//            RelatedContent = commonProperties.RelatedContent.Select(q => new Domain.Models.MediaInfo
//            {
//                Url = q.Url,
//                Type = (Domain.Entities.MediaInfoType)q.Type,
//            }),
//            AnnouncementDate = commonProperties.AnnouncementDate,
//            EstimatedReleaseDate = commonProperties.EstimatedReleaseDate,
//            ReleaseDate = commonProperties.ReleaseDate,
//        };
//    }

//    private Domain.Models.Language Convert(Language language)
//    {
//        return new Domain.Models.Language
//        {
//            Id = language.Id,
//            CodeIso2 = language.CodeIso2,
//            IconId = language.IconId,
//            Deleted = language.Deleted,
//            Name = language.Name,
//        };
//    }

//    private Domain.Models.Genre Convert(Genre genre)
//    {
//        return new Domain.Models.Genre
//        {
//            Id = genre.Id,
//            Name = genre.Name,
//            Deleted = genre.Deleted,
//        };
//    }

//    internal CommonProperties Convert(Domain.Entities.MediaContent.CommonProperties.CommonProperties commonProperties)
//    {
//        var dbCommonProperties = new CommonProperties
//        {
//            Names = commonProperties.Names.Select(q => new NameItem
//            {
//                Value = q.Value,
//                Type = (NameType)q.Type,
//                Language = q.Language.Id,
//            }).ToList(),
//            Preview = commonProperties.Preview == null ? null : new MediaInfo
//            {
//                //Id = 
//                Type = (MediaInfoType)commonProperties.Preview.Type,
//                Url = commonProperties.Preview.Url,
//            },
//            Descriptions = commonProperties.Descriptions.Select(q => new DescriptionItem
//            {
//                IsOriginal = q.IsOriginal,
//                Value = q.Value,
//            }).ToList(),
//            Genres = commonProperties.Genres.Select(q => new GenreProportionItem
//            {
//                GenreId = q.Genre.Id,
//                Proportion = q.Proportion,
//            }).ToList(),
//            RelatedContent = commonProperties.RelatedContent.Select(q => new MediaInfo
//            {
//                Type = (MediaInfoType)q.Type,
//                Url = q.Url,
//            }).ToList(),
//            AnnouncementDate = commonProperties.AnnouncementDate,
//            EstimatedReleaseDate = commonProperties.EstimatedReleaseDate,
//            ReleaseDate = commonProperties.ReleaseDate,
//        };
//        return dbCommonProperties;

//    }
//}