using System;
using System.Threading.Tasks;
using RestSharp;

namespace HorseRacingPredictor.Football.API
{
    internal class Odds : HorseRacingPredictor.Football.Manager.API
    {
        private const string Endpoint = "odds";
        
        /// <summary>
        /// Ottiene le quote per una data specifica
        /// </summary>
        public RestResponse GetOddsByDate(DateTime date, int bookmaker = 8, int page = 1)
        {
            try
            {
                string dateStr = date.ToString("yyyy-MM-dd");
                return ExecuteRequest($"{Endpoint}?date={dateStr}&bookmaker={bookmaker}&page={page}", ApiTypes.Odds);
            }
            catch (Exception ex)
            {
                throw new Exception($"Errore durante il recupero delle quote per la data {date.ToShortDateString()}: {ex.Message}", ex);
            }
        }
        
        /// <summary>
        /// Versione asincrona di GetOddsByDate
        /// </summary>
        public async Task<RestResponse> GetOddsByDateAsync(DateTime date, int bookmaker = 8, int page = 1)
        {
            try
            {
                string dateStr = date.ToString("yyyy-MM-dd");
                return await ExecuteRequestAsync($"{Endpoint}?date={dateStr}&bookmaker={bookmaker}&page={page}");
            }
            catch (Exception ex)
            {
                throw new Exception($"Errore durante il recupero asincrono delle quote per la data {date.ToShortDateString()}: {ex.Message}", ex);
            }
        }
        
        /// <summary>
        /// Ottiene le quote per una partita specifica
        /// </summary>
        public RestResponse GetOddsByFixture(int fixtureId, int bookmaker = 8)
        {
            try
            {
                return ExecuteRequest($"{Endpoint}?fixture={fixtureId}&bookmaker={bookmaker}", ApiTypes.Odds);
            }
            catch (Exception ex)
            {
                throw new Exception($"Errore durante il recupero delle quote per la partita {fixtureId}: {ex.Message}", ex);
            }
        }
    }
}
