using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

namespace Baya.Infrastructure.Persistence.ValueConversion;

/// <summary>
/// SQL Server's <c>datetime2</c> carries no timezone, so EF's provider returns <see cref="DateTimeKind.Unspecified"/>
/// on read even though the value was always written as UTC — leaving it that way makes System.Text.Json omit the
/// trailing <c>Z</c>, and clients then misparse the instant as local time. Re-tags the <see cref="DateTimeKind"/> as
/// <see cref="DateTimeKind.Utc"/> on read; the value itself is never altered.
/// </summary>
internal sealed class UtcDateTimeConverter()
    : ValueConverter<DateTime, DateTime>(
        v => v,
        v => DateTime.SpecifyKind(v, DateTimeKind.Utc));
