package at.procon.dip.ingestion.mail;

import java.util.Map;
import org.junit.jupiter.api.Test;

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

class MailProviderEnvelopeAttributesTest {

    @Test
    void shouldRoundTripGenericProviderEnvelopeThroughAttributes() {
        GenericMailProviderEnvelope envelope = new GenericMailProviderEnvelope(
                MailProviderType.MICROSOFT_GRAPH,
                "mailbox-a",
                "Inbox/Subfolder",
                "provider-message-42",
                "provider-thread-7",
                Map.of("tenant", "demo")
        );

        Map<String, String> attributes = MailProviderEnvelopeAttributes.merge(Map.of("subject", "Hello"), envelope);
        GenericMailProviderEnvelope restored = MailProviderEnvelopeAttributes.fromAttributes(attributes);

        assertThat(restored.providerType()).isEqualTo(MailProviderType.MICROSOFT_GRAPH);
        assertThat(restored.accountKey()).isEqualTo("mailbox-a");
        assertThat(restored.folderKey()).isEqualTo("Inbox/Subfolder");
        assertThat(restored.providerMessageKey()).isEqualTo("provider-message-42");
        assertThat(restored.providerThreadKey()).isEqualTo("provider-thread-7");
        assertThat(restored.providerAttributes()).containsEntry("tenant", "demo");
    }
}
