
using System.Net.Http.Headers;

namespace WorkFlowCheck.Web.Services
{

    public class BaseService
    {
        private readonly IHttpContextAccessor _httpContextAccessor;
        public readonly HttpClient _httpClient;
        public readonly IConfiguration _configuration;


        public BaseService(HttpClient httpClient, IConfiguration configuration, IHttpContextAccessor httpContextAccessor)
        {
            _httpClient = httpClient;
            _configuration = configuration;
            _httpContextAccessor = httpContextAccessor;

            var apiBaseUrl = configuration["ApiBaseUrl"]; // API-cím elérése a konfigurációból
            _httpClient.BaseAddress = new Uri(apiBaseUrl);

            var apiKey = configuration["ApiKey"];
            _httpClient.DefaultRequestHeaders.Add("X-Api-Key", apiKey);

            var jwtToken = _httpContextAccessor.HttpContext?.Request.Cookies["AuthToken"];
            if (!string.IsNullOrEmpty(jwtToken))
            {
                _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", jwtToken);
            }
        }
    }
}
