using System.Text.Json;
using PaydayFrontend.Models;

namespace PaydayFrontend.Services;

public interface IUniversityService
{
    public Task<List<University>> GetAllUniversity(); 
    public Task<List<University>> GetDirectionsByUniversityId(); 
}

public class UniversityService : IUniversityService
{
    private readonly HttpClient _httpClient;

    public UniversityService(HttpClient httpClient)
    {
        _httpClient = httpClient;
        _httpClient.BaseAddress = new Uri("https://payday.zetcraft.ru");
    }

    public async Task<List<University>> GetAllUniversity()
    {
        var response = await _httpClient.GetAsync("v1/public/university");
        var result = await response.Content.ReadAsStringAsync();
        var university = JsonSerializer.Deserialize<List<University>>(result, new JsonSerializerOptions
        {
            PropertyNameCaseInsensitive = true
        });
        return university;
    }

    public async Task<List<University>> GetDirectionsByUniversityId()
    {
        var response = await _httpClient.GetAsync("v1/public/university");
        var result = await response.Content.ReadAsStringAsync();
        var university = JsonSerializer.Deserialize<List<University>>(result, new JsonSerializerOptions
        {
            PropertyNameCaseInsensitive = true
        });
        return university;
    }
}