using AIImages.Helpers;
using Verse;

namespace AIImages.Components
{
    /// <summary>
    /// Компонент для хранения данных AI-сгенерированного портрета пешки
    /// </summary>
    public class PawnPortraitComp : ThingComp
    {
        /// <summary>
        /// Путь к сохраненному портрету
        /// </summary>
        public string PortraitPath { get; set; }

        /// <summary>
        /// Есть ли сохраненный портрет
        /// </summary>
        public bool HasPortrait => !string.IsNullOrEmpty(PortraitPath);

        /// <summary>
        /// Сохранение/загрузка данных
        /// </summary>
        public override void PostExposeData()
        {
            base.PostExposeData();

            string portraitPath = PortraitPath;
            bool isSaving = Scribe.mode == LoadSaveMode.Saving;
            bool isLoading = Scribe.mode == LoadSaveMode.LoadingVars;

            DebugLogger.Log(
                $"[AI Images] PostExposeData for {parent?.LabelShort} - Mode: {Scribe.mode}, Current path: '{PortraitPath}'"
            );

            Scribe_Values.Look(ref portraitPath, "aiPortraitPath", null);

            if (isSaving)
            {
                DebugLogger.Log(
                    $"[AI Images] Saving portrait path for {parent?.LabelShort}: '{portraitPath}'"
                );
            }
            else if (isLoading)
            {
                DebugLogger.Log(
                    $"[AI Images] Loading portrait path for {parent?.LabelShort}: '{portraitPath}'"
                );
            }

            PortraitPath = portraitPath;

            DebugLogger.Log(
                $"[AI Images] PostExposeData completed for {parent?.LabelShort} - Final path: '{PortraitPath}', HasPortrait: {HasPortrait}"
            );
        }
    }
}
