package com.lingniu.ingest.api.event;

import com.lingniu.ingest.api.ProtocolId;
import org.junit.jupiter.api.Test;

import java.time.Instant;
import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;

class RawArchiveKeysTest {

    @Test
    void keyDateUsesShanghaiBusinessDayInsteadOfUtcDay() {
        String key = RawArchiveKeys.key(
                Instant.parse("2026-06-22T16:30:00Z"),
                ProtocolId.GB32960,
                "VIN001",
                "event-1");

        assertThat(key).isEqualTo("2026/06/23/GB32960/VIN001/event-1.bin");
    }

    @Test
    void keyForRawArchiveUsesPrecomputedMetadataKey() {
        VehicleEvent.RawArchive raw = new VehicleEvent.RawArchive(
                "event-1",
                "VIN001",
                ProtocolId.GB32960,
                Instant.parse("2026-06-22T16:30:00Z"),
                Instant.parse("2026-06-22T16:30:00Z"),
                "trace-1",
                Map.of(RawArchiveKeys.META_KEY, "precomputed/key.bin"),
                0x02,
                0,
                new byte[]{0x23, 0x23});

        assertThat(RawArchiveKeys.key(raw)).isEqualTo("precomputed/key.bin");
    }
}
