using System.Text.Json; using System.Text.Json.Nodes; using FsTool; using FsTool.Helpers; namespace FsTool.Tasks { public partial class RegionTasks { /// /// Retrieves all stores within the specified region, ensuring the request is authenticated. /// /// The HTTP client used to perform the request. /// The region identifier to query. /// A list of stores, or an empty list when the call fails or returns no data. public static async Task> GetStoresInRegionAsync(HttpClient httpClient, int regionId) { await AuthHelper.EnsureAuthenticationAsync(httpClient); var uri = string.Format(Endpoints.RegionStores, regionId); var response = await httpClient.GetAsync(uri); var responseBody = await response.Content.ReadAsStringAsync(); // handle unsuccessful response if (!response.IsSuccessStatusCode) { await Console.Error.WriteLineAsync($"Region stores retrieval failed ({(int)response.StatusCode} {response.ReasonPhrase}): {responseBody}"); return []; } Console.WriteLine($"Stores in region {regionId}:"); Console.WriteLine(responseBody); var root = JsonNode.Parse(responseBody); if (root == null) return []; // Deserialize JsonNode to List var opts = new JsonSerializerOptions { PropertyNameCaseInsensitive = true, PropertyNamingPolicy = null // <── WICHTIG }; return root["stores"].Deserialize>(opts) ?? []; } } }