package de.votian.services.service;

import de.votian.services.dto.JobListRowDto;
import org.junit.jupiter.api.Test;

import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.util.List;

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

class JobListExportServiceTest {

    private final JobListExportService jobListExportService = new JobListExportService();

    @Test
    void createCsvUsesLegacyColumnsAndEscapesText() {
        JobListRowDto row = new JobListRowDto();
        row.setId(42L);
        row.setStatus(9);
        row.setOrderTime(LocalDateTime.of(2026, 3, 27, 8, 15));
        row.setFinishTime(LocalDateTime.of(2026, 3, 27, 10, 45));
        row.setCustomerName("ACME \"Nord\"");
        row.setCostCenterName("HQ / Berlin");
        row.setCommissionNo("K-123");
        row.setPickupName("Rampe 1");
        row.setDeliveryName("Tor 2\nEbene 3");
        row.setCourierSid("CR-7");
        row.setTotalPrice(new BigDecimal("123.45"));
        row.setExported(true);
        row.setVehicleTypeId(3);

        String csv = new String(
                jobListExportService.createCsv("Auftragsliste", List.of(row)),
                StandardCharsets.UTF_8
        );

        assertThat(csv).startsWith("Auftragsliste\nAuftrag;Status;Auftragszeit;");
        assertThat(csv).contains("42;\"Abgeschlossen\";\"27.03.2026 08:15\";\"27.03.2026 10:45\"");
        assertThat(csv).contains("\"ACME \"\"Nord\"\"\";\"HQ / Berlin\";\"K-123\"");
        assertThat(csv).contains("\"Tor 2 Ebene 3\";\"CR-7\";\"123.45\";Ja;\"Typ 3\"");
    }
}
