package hozza.network.services;

import hozza.network.models.twitch.repositories.MariaPersonRepository;
import hozza.network.models.twitch.repositories.MariaStreamerRepository;
import hozza.network.models.twitch.repositories.MariaWatchingRepository;
import hozza.network.models.twitch.result.IStreamerCountry;
import hozza.network.models.twitch.result.IWatchingDayOfWeek;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StatService
{
    private final MariaStreamerRepository streamerRepository;
    private final MariaPersonRepository personRepository;
    private final MariaWatchingRepository watchingRepository;

    @Autowired
    public StatService(MariaStreamerRepository streamerRepository, MariaPersonRepository personRepository, MariaWatchingRepository watchingRepository) {
        this.streamerRepository = streamerRepository;
        this.personRepository = personRepository;
        this.watchingRepository = watchingRepository;
    }

    public int getRelationCount()
    {
        try
        {
            return (int)this.watchingRepository.getWatchingCount();
        }
        catch(Exception e)
        {
            return 0;
        }
    }

    public int getStreamerCount()
    {
        try
        {
            return (int)this.streamerRepository.getStreamerCount();
        }
        catch(Exception e)
        {
            return 0;
        }
    }

    public int getRelationCountToday()
    {
        try
        {
            return (int)this.watchingRepository.getWatchingCountToday();
        }
        catch(Exception e)
        {
            return 0;
        }
    }

    public int getViewerCount()
    {
        try
        {
            return (int)this.personRepository.getPersonCount();
        }
        catch(Exception e)
        {
            return 0;
        }
    }

    public int getViewerCountToday()
    {
        try
        {
            return (int)this.personRepository.getPersonCountToday();
        }
        catch(Exception e)
        {
            return 0;
        }
    }

    public List<IWatchingDayOfWeek> getWatchingDayOfWeek()
    {
        return this.watchingRepository.countAllStatisticsByDayOfWeek();
    }

    public List<IStreamerCountry> getStreamerCountry()
    {
        return this.streamerRepository.getStreamersCountry();
    }
}
