package io.delphiplatform.api.v3.bigtable.reader;

import com.google.cloud.bigtable.data.v2.models.Row;

import org.springframework.stereotype.Service;

import io.delphiplatform.api.v3.bigtable.entity.SpotifyPlaylistFollowersDaily;
import lombok.extern.slf4j.Slf4j;

import static io.delphiplatform.api.v3.bigtable.reader.BigtableColumns.FOLLOWERS;
import static io.delphiplatform.api.v3.bigtable.reader.BigtableColumns.PLAYLIST_ID;

@Slf4j
@Service
public class SpotifyPlaylistFollowersDailyReader extends BigtableEntityReader<SpotifyPlaylistFollowersDaily> {

    @Override
    public SpotifyPlaylistFollowersDaily readRow(Row row) {
        SpotifyPlaylistFollowersDaily followersDaily = new SpotifyPlaylistFollowersDaily();

        followersDaily.setDate(readDate(row));
        followersDaily.setPlaylistId(readString(row, PLAYLIST_ID));
        
        String followersStr = readString(row, metrics, FOLLOWERS);
        followersDaily.setFollowers(followersStr != null ? Long.valueOf(followersStr) : null);

        return followersDaily;
    }

    @Override
    public Class<SpotifyPlaylistFollowersDaily> getParsedClass() {
        return SpotifyPlaylistFollowersDaily.class;
    }
}
