using System;
using System.Threading.Tasks;
using HorseRacingPredictor.Football.Manager;
using RestSharp;

namespace HorseRacingPredictor.Football.API
{
    internal class Fixture : HorseRacingPredictor.Football.Manager.API
    {
        private const string Endpoint = "fixtures";
        
        /// <summary>
        /// Ottiene le partite per una data specifica
        /// </summary>
        public new RestResponse GetFixturesByDate(DateTime date)
        {
            try
            {
                string dateStr = date.ToString("yyyy-MM-dd");
                return ExecuteRequest($"{Endpoint}?date={dateStr}", ApiTypes.Fixtures);
            }
            catch (Exception ex)
            {
                throw new Exception($"Errore durante il recupero delle partite per la data {date.ToShortDateString()}: {ex.Message}", ex);
            }
        }
        
        /// <summary>
        /// Versione asincrona di GetFixturesByDate
        /// </summary>
        public new async Task<RestResponse> GetFixturesByDateAsync(DateTime date)
        {
            try
            {
                string dateStr = date.ToString("yyyy-MM-dd");
                return await ExecuteRequestAsync($"{Endpoint}?date={dateStr}");
            }
            catch (Exception ex)
            {
                throw new Exception($"Errore durante il recupero asincrono delle partite per la data {date.ToShortDateString()}: {ex.Message}", ex);
            }
        }
        
        /// <summary>
        /// Ottiene le partite per un ID specifico
        /// </summary>
        public new RestResponse GetFixtureById(int fixtureId)
        {
            try
            {
                return ExecuteRequest($"{Endpoint}?id={fixtureId}", ApiTypes.Fixtures);
            }
            catch (Exception ex)
            {
                throw new Exception($"Errore durante il recupero della partita con ID {fixtureId}: {ex.Message}", ex);
            }
        }
    }
}
