using System.Security.Cryptography;

namespace PhotoHost
{
    public class ImageFile
    {
        // The image data as byte array, initialized via the constructor
        public byte[] Data { get; init; } = Array.Empty<byte>();

        // File extension (.jpg, .png), initialized via the constructor
        public string Extension { get; init; } = string.Empty;

        // Unique ETag for the file
        public string ETag { get; }

        // Constructor that assigns properties and generates the ETag
        public ImageFile(byte[] data, string extension)
        {
            Data = data ?? throw new ArgumentNullException(nameof(data));
            Extension = extension ?? throw new ArgumentNullException(nameof(extension));
            ETag = GenerateETag(data); // Generate ETag based on file data
        }

        // Generate a unique ETag for the file using the more efficient HashData method
        private static string GenerateETag(byte[] data)
        {
            // Use the static HashData method for better performance
            var hash = SHA256.HashData(data);
            return Convert.ToBase64String(hash);
        }
    }
}
