using Butter.Dtos.Settings;
using Microsoft.Extensions.Options;

namespace MilkStream.Services;

public class SettingsServiceOptions {
    public string BaseUrl { get; set; } = string.Empty;
}

public class SettingsService {
    HttpClient client;

    public SettingsService(IOptions<SettingsServiceOptions> options) {
        client             = new();
        client.BaseAddress = new(options.Value.BaseUrl);
    }

    public async Task<List<SettingsDto>> GetAllSettings(string accessToken) {
        client.DefaultRequestHeaders.Authorization = new("Bearer", accessToken);

        var response = await client.GetAsync("api/settings/get-all");

        if (response.IsSuccessStatusCode) {
            return await response.Content.ReadFromJsonAsync<List<SettingsDto>>() ?? new List<SettingsDto>();
        }

        return new List<SettingsDto>();
    }
}
