package testdata;

import de.accso.flexinale.FlexinaleDistributedApplicationTestdata;
import de.accso.flexinale.common.shared_kernel.DoNotCheckInArchitectureTests;
import de.accso.flexinale.ticketing.domain.dao.KontingentDao;
import de.accso.flexinale.ticketing.domain.dao.TicketDao;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;

import static testdata.DatabaseConfig.*;

@SpringBootTest(classes = {FlexinaleDistributedApplicationTestdata.class})
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
@TestPropertySource(properties = {
        dataBaseUrlKey     + " = " + databaseTicketing,
        dataBaseDDLAutoKey + " = " + dataBaseDDLAuto_Update
})
@ActiveProfiles({ "testdata", "testdata-ticketing" })
@DoNotCheckInArchitectureTests
@SuppressWarnings("NewClassNamingConvention")
class TicketsAndKontingenteDatabaseCleaner {

    @Autowired
    private TicketDao ticketDao;

    @Autowired
    private KontingentDao kontingentDao;

    @Test
    void deleteAllTicketsAndKontingenteFromDatabase() {
        internal_deleteAllTicketsAndKontingenteFromDatabase(ticketDao, kontingentDao);
    }

    static void internal_deleteAllTicketsAndKontingenteFromDatabase(final TicketDao ticketDao,
                                                                    final KontingentDao kontingentDao) {
        ticketDao.deleteAll();
        kontingentDao.deleteAll();
    }
}
