# Underground Endpoint QC Feature

## Overview
This feature checks that all underground segments have either a pole or an access point at both endpoints. This ensures proper network connectivity and infrastructure planning.

## Implementation Details

### Backend (`/Backend/qc/underground_endpoints.go`)
- **Main Function**: `CheckUndergroundEndpoints()` - validates underground segments
- **API Endpoints**:
  - `GET /api/qc/underground-endpoints` - Full QC summary
  - `GET /api/qc/underground-endpoints/invalid` - Only invalid segments
  - `POST /api/qc/underground-endpoints/update-flags` - Update QC flags in database

### Frontend Integration
- **Button**: "Underground Endpoint QC" button added to control panel
- **Visual Feedback**: Invalid segments highlighted in purple with dashed lines
- **Popup Information**: Shows segment ID, endpoint details, and specific issues

### Key Features
1. **Spatial Analysis**: Uses 10-meter buffer (~0.0001 degrees) to find nearby poles/access points
2. **Geometry Support**: Handles both LineString and MultiLineString geometries
3. **Database Integration**: Updates QC flags for invalid segments
4. **Visual Mapping**: Highlights problematic segments on the map
5. **Detailed Reporting**: Shows which endpoints are missing and what type of infrastructure is nearby

### QC Validation Logic
For each underground segment:
1. Extract start and end coordinates from geometry
2. Search for poles and access points within buffer distance
3. Check if both endpoints have adjacent infrastructure
4. Report specific issues (missing start/end endpoints)
5. Update database with QC flag if issues found

### Usage
1. Select a market and zone from dropdowns
2. Click "Underground Endpoint QC" button
3. View results in the QC result panel
4. Invalid segments will be highlighted on the map in purple
5. Click on highlighted segments for detailed popup information

### Database Schema Requirements
- Segments table with `segment_type = 'underground'` (case insensitive)
- Poles table with point geometries
- Access points table with point geometries
- QC flag column for marking invalid segments

This feature follows the same patterns as other QC modules in the application and integrates seamlessly with the existing infrastructure.