ImageSearchResult.cs

using System;
using System.Collections.Generic;
 
#nullable enable
 
namespace GenXdev.Helpers
{
    public class ImageSearchResult
    {
        // Core data properties only
        public string Path { get; set; } = string.Empty;
        public int Width { get; set; }
        public int Height { get; set; }
        public PeopleResult People { get; set; } = new PeopleResult();
        public ObjectsResult Objects { get; set; } = new ObjectsResult();
        public MetadataResult Metadata { get; set; } = new MetadataResult();
        public DescriptionResult Description { get; set; } = new DescriptionResult();
        public ScenesResult Scenes { get; set; } = new ScenesResult();
        public List<string> Keywords { get; set; } = new List<string>();
 
        /// <summary>
        /// Creates an ImageSearchResult with the provided data
        /// </summary>
        public static ImageSearchResult CreateWithCachedProperties(
            string path,
            int width,
            int height,
            object people,
            object objects,
            object metadata,
            object description,
            object scenes,
            object keywords,
            object? fileSize,
            object? lastWriteTime)
        {
            return new ImageSearchResult
            {
                Path = path ?? string.Empty,
                Width = width,
                Height = height,
                Keywords = keywords as List<string> ?? new List<string>(),
                People = people as PeopleResult ?? new PeopleResult(),
                Objects = objects as ObjectsResult ?? new ObjectsResult(),
                Metadata = metadata as MetadataResult ?? new MetadataResult(),
                Description = description as DescriptionResult ?? new DescriptionResult(),
                Scenes = scenes as ScenesResult ?? new ScenesResult()
            };
        }
 
        public override string ToString()
        {
            var name = System.IO.Path.GetFileName(Path);
            if (string.IsNullOrEmpty(name)) name = "Unknown";
 
            var parts = new List<string>();
            parts.Add($"{name} ({Width}x{Height})");
 
            if (People != null && People.count > 0)
                parts.Add($"{People.count} faces");
 
            if (Objects != null && Objects.count > 0)
                parts.Add($"{Objects.count} objects");
 
            if (Scenes != null && !string.IsNullOrEmpty(Scenes.label))
                parts.Add($"{Scenes.label} scene");
 
            return string.Join(" - ", parts);
        }
    }
 
    public class PeopleResult
    {
        public string faces { get; set; } = string.Empty;
        public bool success { get; set; }
        public int count { get; set; }
        public List<FacePrediction> predictions { get; set; } = new List<FacePrediction>();
    }
 
    public class FacePrediction
    {
        public double confidence { get; set; }
        public string userid { get; set; } = string.Empty;
        public int y_min { get; set; }
        public int x_min { get; set; }
        public int y_max { get; set; }
        public int x_max { get; set; }
    }
 
    public class ObjectsResult
    {
        public int count { get; set; }
        public List<ObjectPrediction> objects { get; set; } = new List<ObjectPrediction>();
        public Dictionary<string, int> object_counts { get; set; } = new Dictionary<string, int>();
    }
 
    public class ObjectPrediction
    {
        public double confidence { get; set; }
        public string label { get; set; } = string.Empty;
        public int y_min { get; set; }
        public int x_min { get; set; }
        public int y_max { get; set; }
        public int x_max { get; set; }
    }
 
    public class MetadataResult
    {
        public Dictionary<string, object> DateTime { get; set; } = new Dictionary<string, object>();
        public Dictionary<string, object> Exposure { get; set; } = new Dictionary<string, object>();
        public Dictionary<string, object> Camera { get; set; } = new Dictionary<string, object>();
        public Dictionary<string, object> GPS { get; set; } = new Dictionary<string, object>();
        public Dictionary<string, object> Other { get; set; } = new Dictionary<string, object>();
        public Dictionary<string, object> Author { get; set; } = new Dictionary<string, object>();
        public BasicMetadata Basic { get; set; } = new BasicMetadata();
    }
 
    public class BasicMetadata
    {
        public string? Format { get; set; }
        public string? PixelFormat { get; set; }
        public int? Height { get; set; }
        public double? HorizontalResolution { get; set; }
        public int? Width { get; set; }
        public long? FileSizeBytes { get; set; }
        public string? FileExtension { get; set; }
        public double? VerticalResolution { get; set; }
        public string? FileName { get; set; }
    }
 
    public class DescriptionResult
    {
        public bool has_explicit_content { get; set; }
        public bool has_nudity { get; set; }
        public string picture_type { get; set; } = string.Empty;
        public string overall_mood_of_image { get; set; } = string.Empty;
        public string style_type { get; set; } = string.Empty;
        public List<string> keywords { get; set; } = new List<string>();
        public string short_description { get; set; } = string.Empty;
        public string long_description { get; set; } = string.Empty;
    }
 
    public class ScenesResult
    {
        public bool success { get; set; }
        public string scene { get; set; } = string.Empty;
        public double confidence { get; set; }
        public string label { get; set; } = string.Empty;
        public double confidence_percentage { get; set; }
        public string processed_at { get; set; } = string.Empty;
    }
}