using FluentAssertions;

public class DataLakeEventParserTests
{
    [Fact]
    public void ParseObservationRow_LegacyMinimalPayload_UsesFallbackFields()
    {
        var encounterId = Guid.NewGuid();
        var payload = $$"""{"code":"HEART_RATE","value":80,"encounterId":"{{encounterId}}"}""";

        var row = DataLakeEventParser.ParseObservationRow(payload, offset: 42, partition: 2);

        row.EncounterId.Should().Be(encounterId.ToString());
        row.ObservationCode.Should().Be("HEART_RATE");
        row.Value.Should().Be(80);
        row.ObservationId.Should().Be($"legacy:{encounterId}:42");
        row.PatientId.Should().BeEmpty();
        row.Unit.Should().BeEmpty();
        row.Source.Should().BeEmpty();
        row.RecordedAt.Should().BeEmpty();
        row.KafkaPartition.Should().Be(2);
        row.KafkaOffset.Should().Be(42);
    }

    [Fact]
    public void ParseObservationRow_FullPayload_ParsesAllFields()
    {
        var payload = """
            {
              "observationId": "20facb3e-3dcb-46dd-8b81-0fa98cf097e6",
              "encounterId": "d4a0bfa6-3f3c-4dc3-a0d5-f08b574a7cb4",
              "patientId": "eff74ea8-8b02-4a45-8c85-e28604247cc0",
              "mrn": "MRN-000001",
              "observationCode": "HEART_RATE",
              "value": 165,
              "unit": "bpm",
              "source": "DEVICE",
              "recordedAt": "2026-06-23T17:08:20+00:00"
            }
            """;

        var row = DataLakeEventParser.ParseObservationRow(payload, offset: 99, partition: 0);

        row.ObservationId.Should().Be("20facb3e-3dcb-46dd-8b81-0fa98cf097e6");
        row.Mrn.Should().Be("MRN-000001");
        row.Unit.Should().Be("bpm");
        row.RecordedAt.Should().Be("2026-06-23T17:08:20+00:00");
    }
}
