using e_suite.API.Common.models;
using e_suite.CustomerApi.Helper;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;

namespace e_suite.CustomerApi;

public class User
{
    public async Task CreateUser(UserRegistration userRegistration)
    {
        var client = HttpHelper.CreateClient();
        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", ApiSettings.Instance.Token);
        client.BaseAddress = ApiSettings.Instance.BaseUrl;

        var json = JsonSerializer.Serialize(userRegistration);
        var body = new StringContent(json, Encoding.UTF8, "application/json");
        var response = await client.PostAsync("User/user", body);

        if (response.IsSuccessStatusCode)
            return;

        var responseBody = await response.Content.ReadAsStringAsync();

        throw new Exception(responseBody);
    }
}