using FinlyticCore.Dtos.Assets; namespace FinlyticCore.Util; public static class AssetMapper { public static AssetDto ToDto(this AssetEntity entity) { var dtoTags = entity.Tags.Select(t => new TagDto { Id = t.Id, Name = t.Name, Type = t.Type }).ToList(); return entity switch { StockEntity stock => new StockDto { Isin = stock.Isin, Name = stock.Name, Type = stock.Type, InstrumentCategory = stock.InstrumentCategory, HasCfd = stock.HasCfd, ImageId = stock.ImageId, LastUpdatedAt = stock.LastUpdatedAt, Tags = dtoTags, DerivativeProductCategories = stock.DerivativeProductCategories }, EtfEntity etf => new EtfDto { Isin = etf.Isin, Name = etf.Name, Type = etf.Type, InstrumentCategory = etf.InstrumentCategory, HasCfd = etf.HasCfd, ImageId = etf.ImageId, LastUpdatedAt = etf.LastUpdatedAt, Tags = dtoTags, DerivativeProductCategories = etf.DerivativeProductCategories, EtfDescription = etf.EtfDescription, MappedEtfIndexName = etf.MappedEtfIndexName, Subtitle = etf.Subtitle, SearchSubtitle = etf.SearchSubtitle }, CryptoEntity crypto => new CryptoDto { Isin = crypto.Isin, Name = crypto.Name, Type = crypto.Type, InstrumentCategory = crypto.InstrumentCategory, HasCfd = crypto.HasCfd, ImageId = crypto.ImageId, LastUpdatedAt = crypto.LastUpdatedAt, Tags = dtoTags, Subtitle = crypto.Subtitle, SearchSubtitle = crypto.SearchSubtitle }, BondEntity bond => new BondDto { Isin = bond.Isin, Name = bond.Name, Type = bond.Type, InstrumentCategory = bond.InstrumentCategory, HasCfd = bond.HasCfd, ImageId = bond.ImageId, LastUpdatedAt = bond.LastUpdatedAt, Tags = dtoTags, BondIssuerName = bond.BondIssuerName, SearchSubtitle = bond.SearchSubtitle }, DerivativeEntity deriv => new DerivativeDto { Isin = deriv.Isin, Name = deriv.Name, Type = deriv.Type, InstrumentCategory = deriv.InstrumentCategory, HasCfd = deriv.HasCfd, ImageId = deriv.ImageId, LastUpdatedAt = deriv.LastUpdatedAt, Tags = dtoTags, DerivativeProductCategories = deriv.DerivativeProductCategories, UnderlyingIsin = deriv.UnderlyingIsin }, SyntheticEntity synth => new SyntheticDto { Isin = synth.Isin, Name = synth.Name, Type = synth.Type, InstrumentCategory = synth.InstrumentCategory, HasCfd = synth.HasCfd, ImageId = synth.ImageId, LastUpdatedAt = synth.LastUpdatedAt, Tags = dtoTags, DerivativeProductCategories = synth.DerivativeProductCategories }, _ => throw new NotSupportedException($"Mapping for type {entity.GetType().Name} is not supported.") }; } public static List ToDtoList(this IEnumerable entities) { return entities.Select(e => e.ToDto()).ToList(); } }