toArea($areas[$postcode]); } return $this->toArea($this->fetch($postcode)); } /** * Fetch and cache the full country's postcode-to-station map in one call. */ public function warmAll(): void { $areas = []; foreach ($this->fetchAll() as $row) { $areas[$row['Zip_Code']] = $row; } Cache::forever(self::CACHE_KEY, $areas); } private function fetch(string $postcode): array { $response = $this->client->call('ACS_Area_Find_By_Zip_Code', [ 'Zip_Code' => $postcode, 'Show_Only_Inaccessible_Areas' => 0, 'Country' => 'GR', ])->throwIfError(); $area = $response->tableOutput['Table_Data'][0] ?? null; if (! $area) { throw new AcsApiException("No ACS area found for postcode {$postcode}"); } return $area; } private function fetchAll(): array { $response = $this->client->call('ACS_Area_Find_By_Zip_Code', [ 'Zip_Code' => null, 'Show_Only_Inaccessible_Areas' => 0, 'Country' => 'GR', ])->throwIfError(); return $response->tableOutput['Table_Data'] ?? []; } private function toArea(array $row): AcsArea { return new AcsArea( stationId: $row['Station_ID'], branchId: (int) $row['Branch_ID'], ); } }