package de.accso.flexinale.besucherportal.application.services;

import de.accso.flexinale.FlexinaleModulith2ComponentsApplication;
import de.accso.flexinale.backoffice.domain.dao.FilmDao;
import de.accso.flexinale.backoffice.domain.model.Film;
import de.accso.flexinale.backoffice_api_contract.api_contract.model.FilmTO;
import de.accso.flexinale.common.shared_kernel.DoNotCheckInArchitectureTests;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
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.junit.jupiter.SpringExtension;

import static de.accso.flexinale.shared_code_for_test.TestDataBuilder.createFilm;
import static org.assertj.core.api.Assertions.assertThat;

@SpringBootTest(classes = {FlexinaleModulith2ComponentsApplication.class})
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
@ExtendWith(SpringExtension.class)
@DoNotCheckInArchitectureTests
class FilmServiceTest {

    @Autowired
    FilmService filmService;

    @Autowired
    FilmDao filmDao;

    @Test
    void testFindFilm() {
        // arrange
        Film filmOfBackoffice = createFilm();
        filmDao.save(filmOfBackoffice);

        // act
        FilmTO film = filmService.film(filmOfBackoffice.id());

        // assert
        assertThat(film.titel().raw()).isEqualTo(filmOfBackoffice.titel.raw());
        assertThat(film.imdbUrl().raw()).isEqualTo(filmOfBackoffice.imdbUrl.raw());
        assertThat(film.dauerInMinuten().raw()).isEqualTo(filmOfBackoffice.dauerInMinuten.raw());
    }
}