using System.Drawing;
using AutoMapper;
using MaddoShared;

namespace ImageCatalog_2.Mappings;

/// <summary>
/// AutoMapper profile for mapping between DataModel and PicSettings
/// </summary>
public class DataModelMappingProfile : Profile
{
    public DataModelMappingProfile()
    {
        CreateMap<DataModel, PicSettings>()
            // Paths
            .ForMember(dest => dest.DirectorySorgente, opt => opt.MapFrom(src => src.SourcePath))
            .ForMember(dest => dest.DirectoryDestinazione, opt => opt.MapFrom(src => src.DestinationPath))
            
            // Font and text settings
            .ForMember(dest => dest.DimStandard, opt => opt.MapFrom(src => src.FontSize))
            .ForMember(dest => dest.DimStandardMiniatura, opt => opt.MapFrom(src => src.FontSizeThumbnail))
            .ForMember(dest => dest.IlFont, opt => opt.MapFrom(src => src.FontName))
            .ForMember(dest => dest.Grassetto, opt => opt.MapFrom(src => src.FontBold))
            .ForMember(dest => dest.Posizione, opt => opt.MapFrom(src => src.VerticalPosition))
            .ForMember(dest => dest.Allineamento, opt => opt.MapFrom(src => src.HorizontalAlignment))
            .ForMember(dest => dest.Trasparenza, opt => opt.MapFrom(src => src.TextTransparency))
            .ForMember(dest => dest.Margine, opt => opt.MapFrom(src => src.TextMargin))
            .ForMember(dest => dest.FontColoreRGB, opt => opt.MapFrom(src => ColorTranslator.FromHtml(src.TextColorRGB)))
            
            // Thumbnail settings
            .ForMember(dest => dest.AltezzaSmall, opt => opt.MapFrom(src => src.ThumbnailHeight))
            .ForMember(dest => dest.LarghezzaSmall, opt => opt.MapFrom(src => src.ThumbnailWidth))
            .ForMember(dest => dest.Suffisso, opt => opt.MapFrom(src => src.ThumbnailPrefix))
            .ForMember(dest => dest.CreaMiniature, opt => opt.MapFrom(src => src.CreateThumbnails))
            .ForMember(dest => dest.JpegQualityMin, opt => opt.MapFrom(src => src.JpegQualityThumbnail))
            .ForMember(dest => dest.DimMin, opt => opt.MapFrom(src => src.FontSizeThumbnail))
            
            // Big photo settings
            .ForMember(dest => dest.AltezzaBig, opt => opt.MapFrom(src => src.PhotoBigHeight))
            .ForMember(dest => dest.LarghezzaBig, opt => opt.MapFrom(src => src.PhotoBigWidth))
            .ForMember(dest => dest.FotoGrandeDimOrigina, opt => opt.MapFrom(src => src.KeepOriginalDimensions))
            .ForMember(dest => dest.JpegQuality, opt => opt.MapFrom(src => src.JpegQuality))
            .ForMember(dest => dest.Codice, opt => opt.MapFrom(src => src.BigPhotoSuffix))
            
            // Logo settings
            .ForMember(dest => dest.LogoAggiungi, opt => opt.MapFrom(src => src.AddLogo))
            .ForMember(dest => dest.LogoNomeFile, opt => opt.MapFrom(src => src.LogoFile))
            .ForMember(dest => dest.LogoAltezza, opt => opt.MapFrom(src => src.LogoHeight))
            .ForMember(dest => dest.LogoLarghezza, opt => opt.MapFrom(src => src.LogoWidth))
            .ForMember(dest => dest.LogoMargine, opt => opt.MapFrom(src => src.LogoMargin.ToString()))
            .ForMember(dest => dest.LogoTrasparenza, opt => opt.MapFrom(src => src.LogoTransparency.ToString()))
            .ForMember(dest => dest.LogoPosizioneH, opt => opt.MapFrom(src => src.LogoHorizontalPosition))
            .ForMember(dest => dest.LogoPosizioneV, opt => opt.MapFrom(src => src.LogoVerticalPosition))
            
            // Text content
            .ForMember(dest => dest.TestoFirmaStart, opt => opt.MapFrom(src => src.HorizontalText))
            .ForMember(dest => dest.TestoFirmaStartV, opt => opt.MapFrom(src => src.VerticalText))
            
            // Vertical text settings
            .ForMember(dest => dest.DimVert, opt => opt.MapFrom(src => src.VerticalTextSize))
            .ForMember(dest => dest.MargVert, opt => opt.MapFrom(src => src.VerticalTextMargin))
            
            // Boolean flags
            .ForMember(dest => dest.UsaRotazioneAutomatica, opt => opt.MapFrom(src => src.AutomaticRotation))
            .ForMember(dest => dest.UsaForzaJpg, opt => opt.MapFrom(src => src.ForceJpeg))
            .ForMember(dest => dest.TestoNome, opt => opt.MapFrom(src => src.ShowPhotoNumber))
            .ForMember(dest => dest.NomeData, opt => opt.MapFrom(src => src.ShowDate))
            .ForMember(dest => dest.UsaOrarioTestoApplicare, opt => opt.MapFrom(src => src.AddTime))
            .ForMember(dest => dest.UsaTempoGaraTestoApplicare, opt => opt.MapFrom(src => src.AddRaceTime))
            .ForMember(dest => dest.OverwriteFiles, opt => opt.MapFrom(src => src.OverwriteImages))
            
            // Additional settings
            .ForMember(dest => dest.UsaOrarioMiniatura, opt => opt.MapFrom(src => src.ThumbnailOption == ImageCatalog_2.DataModel.ThumbnailOptionEnum.Time))
            .ForMember(dest => dest.DataPartenza, opt => opt.MapFrom(src => src.RaceStartDate))
            .ForMember(dest => dest.TestoOrario, opt => opt.MapFrom(src => src.TimeLabel))
            .ForMember(dest => dest.TestoMin, opt => opt.MapFrom(src => src.ThumbnailOption == ImageCatalog_2.DataModel.ThumbnailOptionEnum.FileName))
            
            // Thumbnail text options
            .ForMember(dest => dest.AggiungiScritteMiniature, opt => opt.MapFrom(src => src.ThumbnailOption == ImageCatalog_2.DataModel.ThumbnailOptionEnum.Text))
            .ForMember(dest => dest.AggTempoGaraMin, opt => opt.MapFrom(src => src.ThumbnailOption == ImageCatalog_2.DataModel.ThumbnailOptionEnum.RaceTime))
            .ForMember(dest => dest.AggNumTempMin, opt => opt.MapFrom(src => src.ThumbnailOption == ImageCatalog_2.DataModel.ThumbnailOptionEnum.FileNameAndTime))
            
            // Ignore unmapped properties
            .ForMember(dest => dest.DestDir, opt => opt.Ignore())
            .ForMember(dest => dest.SecretDefault, opt => opt.Ignore())
            .ForMember(dest => dest.SecretBig, opt => opt.Ignore())
            .ForMember(dest => dest.SecretSmall, opt => opt.Ignore())
            .ForMember(dest => dest.SecretPathSmall, opt => opt.Ignore())
            .ForMember(dest => dest.SecretPathBig, opt => opt.Ignore())
            .ForMember(dest => dest.FotoRuotaADestra, opt => opt.Ignore())
            .ForMember(dest => dest.FotoRuotaASinistra, opt => opt.Ignore())
            .ForMember(dest => dest.TempMinText, opt => opt.Ignore());
    }
}
