using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Http;
using Newtonsoft.Json;
using Launcher.Models;

namespace Launcher.Services
{
    public class AuthenticationService
    {
        private readonly HttpClient _httpClient;

        public AuthenticationService()
        {
            _httpClient = new HttpClient();
        }

        public async Task<bool> LoginAsync(UserModel user)
        {
            var json = JsonConvert.SerializeObject(new { username = user.Username, password = user.Password });
            var content = new StringContent(json, Encoding.UTF8, "application/json");

            try
            {
                var response = await _httpClient.PostAsync("https://wow.zabgame.ru/wp-json/jwt-auth/v1/token", content);
                if (response.IsSuccessStatusCode)
                {
                    // Логика обработки токена
                    return true;
                }
            }
            catch (Exception ex)
            {
                // Теперь переменная ex используется
                Console.WriteLine($"Ошибка: {ex.Message}");
            }

            return false;
        }
    }
}