shoc-backend/SeaHaven.Services/Helpers/WorkOrderExternalVersion.cs
2026-07-27 14:40:17 -03:00

97 lines
2.8 KiB
C#

using System.Security.Cryptography;
using System.Text;
namespace SeaHaven.Services.Helpers
{
public static class WorkOrderExternalVersion
{
public static string ComputeWorkOrder(WorkOrder value) => Compute(
value.WorkOrderId,
value.Status,
value.Description,
value.Customer,
value.SiteCode,
value.Building,
value.Address,
value.Severity,
value.Priority,
value.AssignedTo,
Format(value.DateReported),
Format(value.ScheduledStart),
Format(value.DueDate),
value.RecordType,
Format(value.CreatedAt),
value.SourceEmailS3Key,
null,
null,
null,
null);
public static string ComputeComment(Comment value) => Compute(
value.WorkOrderId,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
value.RecordType,
Format(value.CreatedAt),
value.SourceEmailS3Key,
value.CommentId,
value.Commenter,
value.Text,
Format(value.IngestedAt));
public static string Compute(params string?[] values)
{
var buffer = new StringBuilder();
foreach (var value in values)
{
var normalized = value ?? string.Empty;
buffer.Append(normalized.Length).Append(':').Append(normalized).Append('|');
}
return Convert.ToHexString(
SHA256.HashData(Encoding.UTF8.GetBytes(buffer.ToString())))
.ToLowerInvariant();
}
private static string? Format(DateTimeOffset? value) =>
value?.ToUniversalTime().ToString("O");
public sealed record WorkOrder(
string WorkOrderId,
string? Status,
string? Description,
string? Customer,
string? SiteCode,
string? Building,
string? Address,
string? Severity,
string? Priority,
string? AssignedTo,
DateTimeOffset? DateReported,
DateTimeOffset? ScheduledStart,
DateTimeOffset? DueDate,
string? RecordType,
DateTimeOffset? CreatedAt,
string? SourceEmailS3Key);
public sealed record Comment(
string WorkOrderId,
string CommentId,
string? RecordType,
string? Commenter,
string? Text,
DateTimeOffset? CreatedAt,
DateTimeOffset? IngestedAt,
string? SourceEmailS3Key);
}
}