using System;
using System.Text.Json.Serialization;
using System.Xml.Serialization;

namespace ImageCatalog_2.Models
{
    /// <summary>
    /// Data Transfer Object for application settings.
    /// Uses attributes to control serialization behavior for both XML (legacy) and JSON (future).
    /// </summary>
    public class SettingsDto
    {
        // New enum to represent thumbnail mode in a single property.
        public enum ThumbnailOptionDto
        {
            None = 0,
            Text = 1,
            FileName = 2,
            Time = 3,
            FileNameAndTime = 4,
            RaceTime = 5
        }

        [JsonPropertyName("ThumbnailOption")]
        [XmlElement("MiniatureModalita")]
        public ThumbnailOptionDto ThumbnailOption { get; set; } = ThumbnailOptionDto.None;

        // Paths
        [JsonPropertyName("SourcePath")]
        [XmlElement("DirSorgente")]
        public string SourcePath { get; set; }

        [JsonPropertyName("DestinationPath")]
        [XmlElement("DirDestinazione")]
        public string DestinationPath { get; set; }

        // Thumbnails
        [JsonPropertyName("CreateThumbnails")]
        [XmlElement("MiniatureCrea")]
        public bool CreateThumbnails { get; set; } = true;

        [JsonPropertyName("ThumbnailPrefix")]
        [XmlElement("MiniatureSuffisso")]
        public string ThumbnailPrefix { get; set; } = "tn_";

        [JsonPropertyName("ThumbnailHeight")]
        [XmlElement("MiniatureAltezza")]
        public int ThumbnailHeight { get; set; } = 350;

        [JsonPropertyName("ThumbnailWidth")]
        [XmlElement("MiniatureLarghezza")]
        public int ThumbnailWidth { get; set; } = 350;

        [JsonPropertyName("FontSizeThumbnail")]
        [XmlElement("FontDimensioneMiniatura")]
        public int FontSizeThumbnail { get; set; } = 50;

        [JsonPropertyName("JpegQualityThumbnail")]
        [XmlElement("CompressioneJpegMiniatura")]
        public int JpegQualityThumbnail { get; set; } = 30;

        [JsonPropertyName("AddTimeToThumbnails")]
        [XmlElement("MiniatureAddOrario")]
        public bool AddTimeToThumbnails { get; set; }

        [JsonPropertyName("ShowFileNameOnThumbnails")]
        [XmlElement("NomeMiniatura")]
        public bool ShowFileNameOnThumbnails { get; set; }

        [JsonPropertyName("AddTextToThumbnails")]
        [XmlElement("MiniatureAddScritta")]
        public bool AddTextToThumbnails { get; set; }

        [JsonPropertyName("AddRaceTimeToThumbnails")]
        [XmlElement("TempoSmall")]
        public bool AddRaceTimeToThumbnails { get; set; }

        [JsonPropertyName("AddNumberAndTimeToThumbnails")]
        [XmlElement("NumTempoSmall")]
        public bool AddNumberAndTimeToThumbnails { get; set; }

        // Big photo
        [JsonPropertyName("BigPhotoSuffix")]
        [XmlElement("FotoCodice")]
        public string BigPhotoSuffix { get; set; } = "";

        [JsonPropertyName("PhotoBigHeight")]
        [XmlElement("FotoAltezza")]
        public int PhotoBigHeight { get; set; } = 2240;

        [JsonPropertyName("PhotoBigWidth")]
        [XmlElement("FotoLarghezza")]
        public int PhotoBigWidth { get; set; } = 2240;

        [JsonPropertyName("KeepOriginalDimensions")]
        [XmlElement("FotoDimOriginali")]
        public bool KeepOriginalDimensions { get; set; }

        [JsonPropertyName("JpegQuality")]
        [XmlElement("CompressioneJpeg")]
        public int JpegQuality { get; set; } = 85;

        // Font
        [JsonPropertyName("FontSize")]
        [XmlElement("FontDimensione")]
        public int FontSize { get; set; } = 20;

        [JsonPropertyName("FontName")]
        [XmlElement("FontNome")]
        public string FontName { get; set; } = "Arial";

        [JsonPropertyName("FontBold")]
        [XmlElement("FontBold")]
        public bool FontBold { get; set; }

        [JsonPropertyName("TextColorRGB")]
        [XmlElement("ColoreTestoRGB")]
        public string TextColorRGB { get; set; } = "Yellow";

        // Text
        [JsonPropertyName("HorizontalText")]
        [XmlElement("TestoTesto")]
        public string HorizontalText { get; set; }

        [JsonPropertyName("VerticalText")]
        [XmlElement("TestoVerticale")]
        public string VerticalText { get; set; }

        [JsonPropertyName("TextTransparency")]
        [XmlElement("TestoTrasparente")]
        public int TextTransparency { get; set; }

        [JsonPropertyName("TextMargin")]
        [XmlElement("TestoMargine")]
        public int TextMargin { get; set; } = 8;

        [JsonPropertyName("VerticalPosition")]
        [XmlElement("TestoPosizione")]
        public string VerticalPosition { get; set; } = "Basso";

        [JsonPropertyName("HorizontalAlignment")]
        [XmlElement("TestoAllineamento")]
        public string HorizontalAlignment { get; set; } = "Centro";

        [JsonPropertyName("VerticalTextSize")]
        [XmlElement("GrandezzaVerticale")]
        public int VerticalTextSize { get; set; } = 20;

        [JsonPropertyName("VerticalTextMargin")]
        [XmlElement("MargineVerticale")]
        public int VerticalTextMargin { get; set; } = 6;

        // Logo/Watermark
        [JsonPropertyName("LogoFile")]
        [XmlElement("MarchioFile")]
        public string LogoFile { get; set; } = "";

        [JsonPropertyName("LogoHeight")]
        [XmlElement("MarchioAltezza")]
        public int LogoHeight { get; set; } = 430;

        [JsonPropertyName("LogoWidth")]
        [XmlElement("MarchioLarghezza")]
        public int LogoWidth { get; set; } = 430;

        [JsonPropertyName("LogoMargin")]
        [XmlElement("MarchioMargine")]
        public int LogoMargin { get; set; } = 290;

        [JsonPropertyName("LogoHorizontalPosition")]
        [XmlElement("MarchioAllOrizzontale")]
        public string LogoHorizontalPosition { get; set; } = "Destra";

        [JsonPropertyName("LogoVerticalPosition")]
        [XmlElement("MarchioAllVerticale")]
        public string LogoVerticalPosition { get; set; } = "Basso";

        [JsonPropertyName("LogoTransparency")]
        [XmlElement("MarchioTrasparenza")]
        public int LogoTransparency { get; set; } = 100;

        [JsonPropertyName("AddLogo")]
        [XmlElement("MarchioAggiungi")]
        public bool AddLogo { get; set; }

        // Color-key transparency settings
        [JsonPropertyName("TransparentColor")]
        [XmlElement("ColoreTrasparente")]
        public string TransparentColor { get; set; } = "#FFFFFF";

        [JsonPropertyName("UseTransparentColor")]
        [XmlElement("UsaColoreTrasparente")]
        public bool UseTransparentColor { get; set; } = false;

        // Selected image processing library (e.g., "System.Graphics" or "ImageSharp")
        [JsonPropertyName("ImageLibrary")]
        [XmlElement("ImageLibrary")]
        public string ImageLibrary { get; set; } = "System.Graphics";

        // Options
        [JsonPropertyName("ForceJpeg")]
        [XmlElement("GeneraleForzaJpg")]
        public bool ForceJpeg { get; set; }

        [JsonPropertyName("AutomaticRotation")]
        [XmlElement("GeneraleRotazioneAutomatica")]
        public bool AutomaticRotation { get; set; }

        [JsonPropertyName("UpdateSubdirectories")]
        [XmlElement("DirSottoDirectory")]
        public bool UpdateSubdirectories { get; set; }

        [JsonPropertyName("AddRaceTime")]
        [XmlElement("TempoGara")]
        public bool AddRaceTime { get; set; }

        [JsonPropertyName("AddTime")]
        [XmlElement("Orario")]
        public bool AddTime { get; set; }

        [JsonPropertyName("TimeLabel")]
        [XmlElement("EtichettaOrario")]
        public string TimeLabel { get; set; } = "";

        [JsonPropertyName("ShowDate")]
        [XmlElement("DataFoto")]
        public bool ShowDate { get; set; }

        [JsonPropertyName("ShowPhotoNumber")]
        [XmlElement("NumeroFoto")]
        public bool ShowPhotoNumber { get; set; }

        [JsonPropertyName("OverwriteImages")]
        [XmlElement("GeneraleSovrascriviFile")]
        public bool OverwriteImages { get; set; }

        // Folder division
        [JsonPropertyName("FilesPerFolder")]
        [XmlElement("DirDividiNumFile")]
        public int FilesPerFolder { get; set; } = 99;

        [JsonPropertyName("FolderSuffix")]
        [XmlElement("DirDividiSuffisso")]
        public string FolderSuffix { get; set; } = "";

        [JsonPropertyName("CounterDigits")]
        [XmlElement("DirDividiNumCifre")]
        public int CounterDigits { get; set; } = 2;

        // Processing
        [JsonPropertyName("ChunkSize")]
        [XmlElement("ChunkSize")]
        public int ChunkSize { get; set; }

        [JsonPropertyName("ThreadsCount")]
        [XmlElement("ThreadsCount")]
        public int ThreadsCount { get; set; }

        // Race date
        [JsonPropertyName("RaceStartDate")]
        [XmlElement("DataPartenza")]
        public DateTime RaceStartDate { get; set; } = DateTime.Now;

        // AI / OCR settings
        [JsonPropertyName("ExtractNumbers")]
        [XmlElement("AI_EstraiNumeri")]
        public bool ExtractNumbers { get; set; }

        [JsonPropertyName("ModelsFolderPath")]
        [XmlElement("AI_CartellaModelli")]
        public string ModelsFolderPath { get; set; }

        [JsonPropertyName("CsvOutputPath")]
        [XmlElement("AI_PercorsoCsv")]
        public string CsvOutputPath { get; set; }
    }
}
