using System.IO;
using Titano.Core.Codecs.Jpeg;
using Titano.Core.Imaging;
using Titano.Core.Import;
using Titano.Core.Metadata;
namespace Titano.App.Tests.Import;
/// Synthetic cards (small JPEGs with Exif) and hand-made plans for the Import tests.
internal static class ImportTestData
{
public static readonly DateTime Start = new(2026, 9, 28, 18, 2, 11);
/// A real JPEG with Exif make, model, body serial and capture time; each seed gives distinct bytes.
public static byte[] Jpeg(DateTime captured, int seed)
{
using var image = new ImageBuffer(32, 24);
var random = new Random(seed);
for (var c = 0; c < 3; c++)
{
var plane = image.Plane(c);
var level = (float)random.NextDouble();
for (var i = 0; i < plane.Length; i++) plane[i] = level * (0.5f + 0.5f * (i % 32) / 32f);
}
var exif = ExifWriter.BuildJpegApp1(new FrameMetadata { Make = "Canon", Model = "Canon EOS R5", BodySerial = "0431", CapturedAt = captured, Iso = 100 });
return JpegEncoder.Encode(image, new JpegEncodeOptions { Quality = 80, App1Segments = [exif[4..]] });
}
/// A card folder with DCIM/100CANON: one series per start time, photos 2 s apart.
public static string Card(string root, int perSession, params DateTime[] starts)
{
var folder = Path.Combine(root, "DCIM", "100CANON");
Directory.CreateDirectory(folder);
var n = 1;
foreach (var start in starts)
{
for (var i = 0; i < perSession; i++, n++)
File.WriteAllBytes(Path.Combine(folder, $"IMG_{n:0000}.JPG"), Jpeg(start.AddSeconds(2 * i), n));
}
return root;
}
public static PlannedItem Item(int n, DateTime captured, long size = 24_000_000, ImportAction action = ImportAction.Copy, Guid? existing = null) => new()
{
SourcePath = $"DCIM/100CANON/IMG_{n:0000}.CR2",
Size = size,
ModifiedUtc = captured,
CapturedAt = captured,
FileName = $"{captured:yyyy-MM-dd_HH-mm-ss}_{n:0000}.CR2",
Action = action,
ExistingFrameId = existing,
};
public static PlannedSession Session(int number, string folder, params PlannedItem[] items) => new()
{
Number = number,
SessionKey = $"card-0000000{number}-key",
CameraMake = "Canon",
CameraModel = "Canon EOS R5",
Format = ImageFileFormat.Cr2,
Start = items[0].CapturedAt,
End = items[^1].CapturedAt,
Folder = folder,
Items = items,
};
public static ImportPlan Plan(long? available, IReadOnlyList? problems = null, params PlannedSession[] sessions) => new()
{
Id = Guid.CreateVersion7(),
SourceRoot = "/card",
DestinationRoot = "/archive",
Sessions = sessions,
Problems = problems ?? [],
AvailableBytes = available,
};
}