# Refactor: register typed HttpClient for Google Maps in DI

**Task**: AZ-374_refactor_typed_httpclient_googlemaps
**Name**: Named HttpClient for GoogleMapsDownloaderV2
**Description**: Register a named `HttpClient` ("GoogleMapsTiles") with default headers + timeout, and have `GoogleMapsDownloaderV2` resolve it via `IHttpClientFactory.CreateClient("GoogleMapsTiles")` everywhere.
**Complexity**: 2 points
**Dependencies**: None
**Component**: Api + Services.TileDownloader
**Tracker**: AZ-374
**Epic**: AZ-350

## Problem

`SatelliteProvider.Services.TileDownloader/GoogleMapsDownloaderV2.cs:51, 107, 369` calls `_httpClientFactory.CreateClient()` in three different code paths (session-token fetch, single-tile download, batch-tile download retry lambda) and sets the `User-Agent` header per call. The factory pools `HttpMessageHandler`s correctly, but the per-call header setup is duplicated and error-prone.

## Outcome

- Single named-client registration in `Program.cs`.
- All three downloader paths resolve `CreateClient("GoogleMapsTiles")`.
- Same outbound HTTP behavior.
- 37 unit + 5 smoke tests stay green.

## Scope

### Included
- Add `services.AddHttpClient("GoogleMapsTiles", c => { c.DefaultRequestHeaders.UserAgent.ParseAdd(USER_AGENT); c.Timeout = TimeSpan.FromSeconds(<existing default>); });` in `Program.cs`.
- Replace three `CreateClient()` calls with `CreateClient("GoogleMapsTiles")`.
- Remove the per-call `UserAgent` setup.

### Excluded
- Migrating to a typed `HttpClient` subclass (deferred).
- Adding Polly or retry policy at the factory level (existing manual retry stays).

## Acceptance Criteria

**AC-1: Single registration**
Given the post-refactor `Program.cs`
When inspected
Then a single `AddHttpClient("GoogleMapsTiles", ...)` registration exists.

**AC-2: Downloader uses the named client**
Given the post-refactor downloader
When grepped for `CreateClient(`
Then all matches use the `"GoogleMapsTiles"` name.

**AC-3: Tests stay green**
Given the post-refactor build
When `scripts/run-tests.sh --smoke` runs
Then all 37 unit + 5 smoke scenarios pass.

## Constraints

- Same outbound `User-Agent` header text.
- Same timeout (use the existing implicit default until C18 wires this to config).

## Risks & Mitigation

**Risk 1: timeout default surprises a slow path**
- *Risk*: setting an explicit timeout may cut off a slow Google Maps response that previously hung indefinitely.
- *Mitigation*: pick a generous default (e.g., 60 s) matching observed worst case; tune via C18.

Full change entry: `_docs/04_refactoring/03-code-quality-refactoring/list-of-changes.md` (C21).
