using System.Text.Encodings.Web; using System.Text.Json; using System.Text.Json.Serialization; namespace Admin.NET.Plugin.AiDOP.DataPlatform.Inbound; internal static class MdpInboundJson { public static readonly JsonSerializerOptions Options = new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping }; } public sealed class MdpInboundReceiveArgs { public string EntityCode { get; init; } = string.Empty; public byte[] RawBody { get; init; } = []; public string AccessKey { get; init; } = string.Empty; public long TenantId { get; init; } public string IdempotencyKey { get; init; } = string.Empty; public string ClientIp { get; init; } = string.Empty; public string Path { get; init; } = string.Empty; public IReadOnlyDictionary Headers { get; init; } = new Dictionary(); } public sealed class MdpInboundOutcome { public int HttpStatus { get; init; } public object Body { get; init; } } public sealed class MdpInboundReceiptData { public string EntityCode { get; set; } = string.Empty; public int Accepted { get; set; } public int Rejected { get; set; } public List RejectedRows { get; set; } = []; public bool IdempotentReplay { get; set; } public string SyncBatchId { get; set; } = string.Empty; public long RequestId { get; set; } public bool TransformEnqueued { get; set; } public int StaleRejected { get; set; } public int EqualTsOverride { get; set; } } public sealed class MdpInboundRejectedRow { public string BizKey { get; set; } public string Reason { get; set; } = string.Empty; } public sealed class MdpInboundSchemaField { public string Name { get; set; } = string.Empty; public string RawKey { get; set; } = string.Empty; public bool Required { get; set; } } public sealed class MdpInboundSchemaData { public string EntityCode { get; set; } = string.Empty; public string BizKeyExpr { get; set; } public List Fields { get; set; } = []; } internal sealed class MdpInboundParsedBatch { public List Rows { get; init; } = []; public string SnapshotId { get; init; } public int? Seq { get; init; } } public sealed class MdpInboundPreparedRow { public Dictionary Dict { get; init; } = new(StringComparer.OrdinalIgnoreCase); public string RawJson { get; init; } = string.Empty; public string BizKey { get; init; } = string.Empty; public string SourceUpdatedAt { get; init; } public string SourceVersion { get; init; } } internal sealed class MdpInboundStgGuardRow { public long Id { get; set; } public string SourceSystem { get; set; } public string SourceRowId { get; set; } public string SourceUpdatedAt { get; set; } public string SourceVersion { get; set; } public string RawData { get; set; } } internal sealed class MdpInboundBatchException : Exception { public int HttpStatus { get; } public string ErrorCode { get; } public MdpInboundBatchException(int httpStatus, string message, string errorCode = null) : base(message) { HttpStatus = httpStatus; ErrorCode = errorCode ?? message; } }