package io.delphiplatform.api.v3.model.playlist;

import com.sonymusic.delphi.etl.apps.proto.Playlists.PlaylistTrackCountryStats;

import org.apache.commons.lang3.reflect.FieldUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Field;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
import java.util.stream.Stream;

import io.delphiplatform.api.v3.bigtable.entity.PlaylistPosition;

class PlaylistPositionTest {

    @Test
    void testFieldsNotChanged_copyConstructorReminder() {
        LocalDate testDate = new Date().toInstant()
            .atZone(ZoneId.systemDefault())
            .toLocalDate();

        PlaylistPosition position = new PlaylistPosition();
        position.setDate(testDate);
        position.setDsp("spotify");
        position.setPlaylistId("playlistId");
        position.setIsrc("isrc");
        position.setCurrent(1L);
        position.setPrevious(1L);
        position.setTrend(0L);
        position.setTrackId("trackId");
        position.setCountryCode("us");
        position.setDaysInPlaylist(5L);
        position.setEarliestPositionDate(testDate);
        position.setLatestPositionDate(testDate);
        position.setPreviousPositionChange14Days(4L);
        position.setTrendChange14Days(1L);
        position.setLastDateChange14Days(testDate);
        position.setPlaylistTrackCountryStats(PlaylistTrackCountryStats.newBuilder().build());

        PlaylistPosition copy = new PlaylistPosition(position);

        Stream.of(copy.getClass().getDeclaredFields())
            .map(Field::getName)
            .forEach(field -> {
                try {
                    Object fieldValue = FieldUtils.readField(copy, field, true);

                    Assertions.assertNotNull(
                        fieldValue,
                        String.format("Field value is null for '%s', probably new field was added to PlaylistPosition class. "
                            + "please update this test AND copy constructor of PlaylistPosition (!)", field)
                    );
                } catch (IllegalAccessException e) {
                    Assertions.fail("Unexpected exception: " + e.getMessage());
                }
            });
    }
}
