package dev.lions.unionflow.server.payment.pispi;

import dev.lions.unionflow.server.payment.pispi.dto.Pacs008Request;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.math.BigDecimal;

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

class Pacs008RequestTest {

    private Pacs008Request request;

    @BeforeEach
    void setUp() {
        request = new Pacs008Request();
        request.setMessageId("UFMSG-ABC123456789");
        request.setCreationDateTime("2026-04-20T10:00:00Z");
        request.setNumberOfTransactions("1");
        request.setEndToEndId("REF-SOUSCRIPTION-001");
        request.setInstrId("UFINS-12345678");
        request.setAmount(new BigDecimal("5000.00"));
        request.setCurrency("XOF");
        request.setDebtorName("Jean Dupont");
        request.setDebtorBic("BCEAOCIAB");
        request.setCreditorName("Mutuelle Solidarité");
        request.setCreditorBic("BCEAOCIAB");
        request.setRemittanceInfo("Cotisation mensuelle");
    }

    @Test
    @DisplayName("toXml contient le messageId")
    void toXml_containsMessageId() {
        String xml = request.toXml();
        assertThat(xml).contains("UFMSG-ABC123456789");
        assertThat(xml).contains("<MsgId>UFMSG-ABC123456789</MsgId>");
    }

    @Test
    @DisplayName("toXml contient le montant")
    void toXml_containsAmount() {
        String xml = request.toXml();
        assertThat(xml).contains("5000.00");
        assertThat(xml).contains("IntrBkSttlmAmt");
    }

    @Test
    @DisplayName("toXml contient le namespace ISO 20022 pacs.008")
    void toXml_containsIso20022Namespace() {
        String xml = request.toXml();
        assertThat(xml).contains("urn:iso:std:iso:20022:tech:xsd:pacs.008.001.10");
    }

    @Test
    @DisplayName("toXml contient le endToEndId")
    void toXml_containsEndToEndId() {
        String xml = request.toXml();
        assertThat(xml).contains("<EndToEndId>REF-SOUSCRIPTION-001</EndToEndId>");
    }

    @Test
    @DisplayName("toXml échappe les caractères XML spéciaux dans les champs texte")
    void toXml_escapesSpecialCharacters() {
        request.setDebtorName("Company & Co <Tag>");
        String xml = request.toXml();
        assertThat(xml).contains("Company &amp; Co &lt;Tag&gt;");
        assertThat(xml).doesNotContain("<Tag>");
    }
}
