using System;
using System.Text.Json.Nodes;
namespace Elwig.Helpers.Weighing {
///
/// Result of a weighing process on an industrial weighing scale
///
public struct WeighingResult {
///
/// Measured gross weight in kg
///
public int? GrossWeight;
///
/// Measured tare weight in kg
///
public int? TareWeight;
///
/// Measured net weight in kg
///
public int? NetWeight;
///
/// Weighing id (or IdentNr) provided by the scale
///
public string? WeighingId;
///
/// Wheighing id (or IdentNr) provided by the scale optionally combined with the current date
///
public string? FullWeighingId;
///
/// Date string provided by the scale
///
public DateOnly? Date;
///
/// Time string provided by the scale
///
public TimeOnly? Time;
/// <[GrossWeight-TaraWeight=]NetWeight/WeighingId/Date/Time>
public override readonly string ToString() {
var w = NetWeight != null ? (GrossWeight != null && TareWeight != null ? $"{GrossWeight}-{TareWeight}=" : "") + $"{NetWeight}kg" : "";
return $"<{w}/{WeighingId}/{Date:yyyy-MM-dd}/{Time:HH:mm}>";
}
public readonly JsonObject ToJson() {
var obj = new JsonObject();
if (FullWeighingId != null) obj["id"] = FullWeighingId;
if (WeighingId != null) obj["nr"] = int.Parse(WeighingId);
if (Date != null) obj["date"] = $"{Date:yyyy-MM-dd}";
if (Time != null) obj["time"] = $"{Time:HH:mm:ss}";
if (GrossWeight != null) obj["gross_weight"] = GrossWeight;
if (TareWeight != null) obj["tare_weight"] = TareWeight;
if (NetWeight != null) obj["net_weight"] = NetWeight;
return obj;
}
}
}