#!/usr/bin/env python3
"""
🛰️ PhotoTrek ASCII Adventure Engine & Procedural Landscape Generator
Generates high-contrast ASCII landscapes, celestial vectors, and expedition telemetry in pure Python.
Zero dependencies. Offline resilient. Ready for terminal, satellite messengers, or Google Colab.
"""

import sys
import math
import argparse

LANDSCAPES = [
  {
    "id": "hood-summit",
    "name": "Mt. Hood Summit & Timberline Transect",
    "category": "Alpine & Volcanic",
    "tags": [
      "mountain",
      "hood",
      "volcano",
      "oregon",
      "timberline",
      "snow",
      "golden hour"
    ],
    "elevation": 14.5,
    "azimuth": 145,
    "scale": 3,
    "description": "Highest peak in Oregon (11,249') with volcanic pinnacle ice and golden hour raking sunbeams across Timberline Lodge.",
    "ascii": "┌─────────────────────────────────────────────────────────────────────────────┐\n│ 🏔️  MT. HOOD SUMMIT (11,249') & TIMBERLINE TRANSECT                         │\n├─────────────────────────────────────────────────────────────────────────────┤\n  .   *   ★ POLARIS (38.5° Alt)   *   .    .   *   .    *   .   *   .\n       ▲  [ ☀️ Solar Elevation: 14.5° | Azimuth: 145.0° ESE | Golden Hour ]\n   ───╱╲───────. · ˙ ˙ · .─────────────────────────────────────────────────────\n     ╱    ╲  . ·             · .   \\  \\  \\  (Volumetric Gold Rays)\n   _╱  Mt. ╲_                   · . \\  \\  \\\n  ╱   Hood   ╲                       · . \\  \\\n ╱ [11,249']  ╲___________________________· . ________________________________\n 🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲\n├─────────────────────────────────────────────────────────────────────────────┤\n│ 🛰️ TELEMETRY: Azimuth 145° | Shadow Factor: 3.86x | Light: Golden Hour Active│\n└─────────────────────────────────────────────────────────────────────────────┘\n  [DEPOT: 08:30 AM] ──► [TIMBERLINE BASE: 11:45 AM] ──► [SUMMIT TRAIL] ──► [RETURN]"
  },
  {
    "id": "columbia-gorge",
    "name": "Columbia River Basalt Gorge & Dam",
    "category": "Gorges & Waterfalls",
    "tags": [
      "gorge",
      "river",
      "columbia",
      "basalt",
      "bonneville",
      "dam",
      "hydro"
    ],
    "elevation": 28,
    "azimuth": 180,
    "scale": 2,
    "description": "Grand 84-mile river canyon carved through basalt layers with hydroelectric clean energy corridors.",
    "ascii": "┌─────────────────────────────────────────────────────────────────────────────┐\n│ 🌊  COLUMBIA RIVER BASALT GORGE & HYDROELECTRIC DAM                         │\n├─────────────────────────────────────────────────────────────────────────────┤\n  *   .   ★ CASSIOPEIA   .   *      .   *   .    ★ VEGA    *   .   *\n                                            ☀️ [ Solar Elev: 28.0° | Azimuth: 180° ]\n        _▲_                                          ╱  ╱  (Gorge Winds)\n       ╱   ╲  Basalt Cliffs                        _╱  _\n  ____╱     ╲_____________________________________╱   ╲_______________________\n ~~~~~~~~~~~~~~~~~~ [ COLUMBIA RIVER TRANSECT: 84 MI ] ~~~~~~~~~~~~~~~~~~~~~~~\n   [BONNEVILLE DAM] ════════════════════════════════► [THE DALLES BASALT]\n 🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲\n├─────────────────────────────────────────────────────────────────────────────┤\n│ 🛰️ TURBINE FLOW: 142k CFS | CLEAN ENERGY: 1,200 MW | RIVER DEPTH: 120 FT    │\n└─────────────────────────────────────────────────────────────────────────────┘\n  [DISCOVERY ROSTER: 48 STUDENTS] • [CITIZEN SCI: WATER QUALITY] • [RETURN: OK]"
  },
  {
    "id": "crater-lake",
    "name": "Crater Lake Caldera & Milky Way Core",
    "category": "Astrophotography & Night Sky",
    "tags": [
      "crater lake",
      "night",
      "milky way",
      "stars",
      "caldera",
      "dark sky",
      "astronomy"
    ],
    "elevation": -8,
    "azimuth": 165,
    "scale": 4,
    "description": "Deepest lake in the United States (1,943') within a collapsed volcanic caldera under Class-1 dark sky sanctuary.",
    "ascii": "┌─────────────────────────────────────────────────────────────────────────────┐\n│ 🌌  CRATER LAKE CALDERA & MILKY WAY CORE RISING                             │\n├─────────────────────────────────────────────────────────────────────────────┤\n       .  *         *  .       .   *   MILKY WAY CORE (Rising 165° SSE)\n  *    .      .   *   ★ POLARIS      .   *       .   *        .\n .          *          *        .         *   .       *   .       *\n───────────────────────────────────────────────────────────────────────────────\n      _▲_             [ WIZARD ISLAND ]            _▲_\n     ╱   ╲                ▲                       ╱   ╲   Caldera Rim\n  __╱     ╲______________╱ ╲_____________________╱     ╲______________________\n ~~~~~~~~~~~~~~~ [ DEEP INDIGO CALDERA WATER: 1,943' ] ~~~~~~~~~~~~~~~~~~~~~~~\n 🗻🗻🗻🗻🗻🗻🗻🗻🗻🗻🗻🗻🗻🗻🗻🗻🗻🗻🗻🗻🗻🗻🗻🗻🗻🗻🗻🗻🗻🗻🗻🗻🗻🗻🗻🗻🗻\n├─────────────────────────────────────────────────────────────────────────────┤\n│ 🛰️ DARK SKY SANCTUARY: BORTLE CLASS 1 | CAMERA: 35mm f/1.4 | ISO 3200 | 25s  │\n└─────────────────────────────────────────────────────────────────────────────┘\n  [EXPEDITION ROSTER: 24 OBSERVERS] • [ZERO LIGHT POLLUTION] • [ZENITH: 01:30 AM]"
  },
  {
    "id": "multnomah-falls",
    "name": "Multnomah Basalt Falls & Benson Bridge",
    "category": "Gorges & Waterfalls",
    "tags": [
      "waterfall",
      "multnomah",
      "falls",
      "bridge",
      "basalt",
      "mist",
      "rainforest"
    ],
    "elevation": 22,
    "azimuth": 155,
    "scale": 2,
    "description": "Two-tiered 620-foot waterfall cascading over columnar basalt with iconic arched stone pedestrian bridge.",
    "ascii": "┌─────────────────────────────────────────────────────────────────────────────┐\n│ 💦  MULTNOMAH BASALT FALLS & BENSON BRIDGE (620' TOTAL DROP)                │\n├─────────────────────────────────────────────────────────────────────────────┤\n         _▲_                   │  │ [Upper Falls 542']\n        ╱   ╲                  │  │\n       ╱     ╲                 │  │ (Misty Spray Rainbow Arc 🌈)\n      ╱ Basalt╲                │  │\n     ╱  Ridge  ╲          ─────┴──┴───── [Benson Footbridge 105']\n    ╱           ╲              │  │\n   ╱             ╲             │  │ [Lower Falls 69']\n  ╱_______________╲~~~~~~~~~~~~┴──┴~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~───────────\n 🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲🌲\n├─────────────────────────────────────────────────────────────────────────────┤\n│ 🛰️ TURBIDITY: 0.8 NTU | WATER TEMP: 51.4°F | GEOLOGY: COLUMBIA RIVER BASALT  │\n└─────────────────────────────────────────────────────────────────────────────┘\n  [FIELD TRIP ROSTER: 48 STUDENTS] • [CITIZEN SCI: MICRO-GRANTS] • [SAFE: 100%]"
  },
  {
    "id": "clean-fleet-bus",
    "name": "Clean Fleet Electric Bus Mountain Ascent",
    "category": "Clean Fleet & Expedition Wayfinding",
    "tags": [
      "bus",
      "electric",
      "transit",
      "clean energy",
      "field trip",
      "school",
      "coppa"
    ],
    "elevation": 18,
    "azimuth": 120,
    "scale": 3,
    "description": "Zero-emission electric school bus navigating mountain pass switchbacks with algorithmic time windows.",
    "ascii": "┌─────────────────────────────────────────────────────────────────────────────┐\n│ 🚌  CLEAN FLEET ELECTRIC BUS EXPEDITION :: CASCADE ASCENT                   │\n├─────────────────────────────────────────────────────────────────────────────┤\n 08:30 AM  [SCHOOL DEPOT]      🚍───────► 09:15 AM [MULTNOMAH FALLS]\n           • Headcount: 48/48               • Photo Window: 45 min\n           • Status: DEPARTED               • Citizen Sci: Water Turbidity\n\n 10:15 AM  [BONNEVILLE DAM]    ─────────► 12:00 PM [TIMBERLINE BASE]\n           • Hydroelectric Tour             • Lunch + Solar Trig Lab\n           • Buffer: +15 min                • Light: Peak Golden Hour\n\n 01:30 PM  [HOOD RIVER PASS]   ─────────► 02:45 PM [CAMPUS ARRIVAL]\n           • Zooniverse Grants: $48.00      • Return Bell: 03:00 PM (SAFE)\n           • Clean EV Battery: 42%          • Total Miles: 118.4 mi\n├─────────────────────────────────────────────────────────────────────────────┤\n│ PROGRESS: [████████████████████████████░░░░░░░░░░] 72% COMPLETE | 0-PII COPPA│\n└─────────────────────────────────────────────────────────────────────────────┘\n  [ZERO PII TRACKING] • [ALGORITHMIC VRPTW SAFETY] • [DISMISSAL BUFFER: +15 MIN]"
  },
  {
    "id": "painted-hills",
    "name": "Painted Hills High Desert Stratification",
    "category": "High Desert & Badlands",
    "tags": [
      "desert",
      "painted hills",
      "oregon",
      "geology",
      "fossil",
      "clay",
      "sunset"
    ],
    "elevation": 8.5,
    "azimuth": 245,
    "scale": 2,
    "description": "Striated red laterite and golden ochre clay hills deposited 35 million years ago in John Day Basin.",
    "ascii": "┌─────────────────────────────────────────────────────────────────────────────┐\n│ 🏜️  PAINTED HILLS HIGH DESERT STRATIFICATION (JOHN DAY BASIN)               │\n├─────────────────────────────────────────────────────────────────────────────┤\n               ☀️ [ Sun: 08.5° | Low Raking Golden Hour Ochre Warmth ]\n                  ╲  ╲  ╲  (Volumetric Long Shadows)\n      ╭────────╮\n    ╭─╯ Laterite ╰─╮          ╭─────────╮\n  ╭─╯ Clay Stratum ╰──────────╯ Ochre Bed╰─╮\n ╭╯  Red & Gold Soil Layers                 ╰─────────────────────────────────\n ─────────────────────────────────────────────────────────────────────────────\n  🌿 Sagebrush & Juniper Desert Transect (John Day Fossil Beds Monument)\n├─────────────────────────────────────────────────────────────────────────────┤\n│ 🛰️ GEOLOGY: OLIGOCENE 33 MA | SOIL: OXIDIZED IRON (FE2O3) & LIGNITE BEDS     │\n└─────────────────────────────────────────────────────────────────────────────┘\n  [HIGH DESERT TEMPERATURE: 74°F] • [HUMIDITY: 18%] • [SHADOW RATIO: 6.7x HEIGHT]"
  },
  {
    "id": "olympic-rainforest",
    "name": "Olympic Rainforest Mossy Canopy",
    "category": "Temperate Rainforest & Coast",
    "tags": [
      "rainforest",
      "olympic",
      "moss",
      "trees",
      "ferns",
      "fog",
      "washington"
    ],
    "elevation": 12,
    "azimuth": 110,
    "scale": 3,
    "description": "Lush temperate rainforest with 200-foot Sitka spruces draped in hanging club moss and sword ferns.",
    "ascii": "┌─────────────────────────────────────────────────────────────────────────────┐\n│ 🌿  OLYMPIC TEMPERATE RAINFOREST & MOSS CANOPY (HOH RIVER VALLEY)           │\n├─────────────────────────────────────────────────────────────────────────────┤\n          . · ˙ ˙ · . [ Filtered Fog Sunlight 12.0° ]\n      . ·             · .    \\  \\  \\  (Misty Crepuscular Beams)\n    ╭─┴─────────────────┴─╮\n   ╱    SITKA SPRUCE       ╲   (250' Canopy)\n  │    draped with moss     │\n ╭┴─────────────────────────┴╮\n │   Club Moss & Lichens     │\n ├───┬───────────────────┬───┤\n │   │  Hoh River Gravel │   │\n └───┴───────────────────┴───┴─────────────────────────────────────────────────\n 🌿🌿🌿🌿🌿🌿🌿🌿🌿🌿🌿🌿 [ Sword Fern Understory: 140\" Annual Rain ] 🌿🌿🌿🌿🌿🌿🌿\n├─────────────────────────────────────────────────────────────────────────────┤\n│ 🛰️ HUMIDITY: 94% | BIOMASS DENSITY: HIGHEST IN NORTH AMERICA | AIR: PRISTINE │\n└─────────────────────────────────────────────────────────────────────────────┘\n  [CANOPY SOUNDSCAPE: 18 dBA] • [ECOSYSTEM HEALTH: EXCELLENT] • [EXPEDITION: OK]"
  },
  {
    "id": "cannon-beach",
    "name": "Haystack Rock & Pacific Sea Stacks",
    "category": "Temperate Rainforest & Coast",
    "tags": [
      "coast",
      "ocean",
      "beach",
      "cannon beach",
      "haystack rock",
      "waves",
      "tides"
    ],
    "elevation": 4.5,
    "azimuth": 260,
    "scale": 3,
    "description": "Iconic 235-foot basalt sea stack rising from Pacific surf with marine tidal pools and tufted puffin colonies.",
    "ascii": "┌─────────────────────────────────────────────────────────────────────────────┐\n│ 🌊  HAYSTACK ROCK & PACIFIC COASTAL SEA STACKS (CANNON BEACH)               │\n├─────────────────────────────────────────────────────────────────────────────┤\n                                      ☀️ [ Sunset Horizon: 04.5° WSW ]\n                                         . · ˙ ˙ · .\n           ▲ [Haystack Rock 235']       . ·   🌊    · .\n          ╱█╲                          . ·             · .\n        _╱███╲_     _▲_\n       ╱███████╲   ╱███╲ (The Needles)\n ~~~~~╱█████████╲─╱█████╲~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n ~~~~~~~~~~~~~~~ [ PACIFIC INTERTIDAL REEF & SURF ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~\n ─────────────────────────────────────────────────────────────────────────────\n  🏖️ Sandy Beach Transect • Tufted Puffin Sanctuary (Oregon Islands NWR)\n├─────────────────────────────────────────────────────────────────────────────┤\n│ 🛰️ TIDE STATUS: LOW TIDE (-1.2 FT) | SURF SWELL: 4-6 FT | PUFFIN COUNT: 84   │\n└─────────────────────────────────────────────────────────────────────────────┘\n  [TIDAL POOL LAB: ACTIVE] • [INTERTIDAL BIOLOGY: 100%] • [SUNSET: 07:42 PM]"
  }
]

def list_landscapes():
    print("═" * 78)
    print("🛰️  PHOTOTREK PREGENERATED ASCII LANDSCAPE ARCHIVE")
    print("═" * 78)
    for idx, item in enumerate(LANDSCAPES, 1):
        print(f"[{idx}] {item['name']:<42} | Category: {item['category']}")
        print(f"    Tags: {', '.join(item['tags'])}")
        print(f"    {item['description']}")
        print("-" * 78)

def search_landscapes(query):
    query = query.lower()
    matches = [
        item for item in LANDSCAPES
        if query in item['name'].lower() 
        or query in item['category'].lower() 
        or any(query in tag for tag in item['tags'])
        or query in item['description'].lower()
    ]
    return matches

def render_landscape(item):
    print(item['ascii'])

def main():
    parser = argparse.ArgumentParser(description="PhotoTrek ASCII Adventure & Telemetry Engine")
    parser.add_argument("--list", action="store_true", help="List all available pregenerated landscapes")
    parser.add_argument("--search", type=str, help="Search landscapes by keyword or biome")
    parser.add_argument("--id", type=str, default="hood-summit", help="Render landscape by ID (default: hood-summit)")
    
    args = parser.parse_args()

    if args.list:
        list_landscapes()
        return

    if args.search:
        matches = search_landscapes(args.search)
        if not matches:
            print(f"No landscapes found matching '{args.search}'. Showing full catalog:")
            list_landscapes()
        else:
            print(f"Found {len(matches)} matching vista(s) for '{args.search}':\n")
            for m in matches:
                render_landscape(m)
                print("\n" + "=" * 78 + "\n")
        return

    selected = next((l for l in LANDSCAPES if l['id'] == args.id), None)
    if selected:
        render_landscape(selected)
    else:
        print(f"Landscape ID '{args.id}' not found. Defaulting to Mt. Hood:")
        render_landscape(LANDSCAPES[0])

if __name__ == "__main__":
    main()
