# Admin API: Get All Lines

## Endpoint
```
GET /admin/lines
```

## Description
Retrieves all lines configured for the admin's company. Lines are organized by line name and area, with optional filtering by area.

## Authentication
- **Required**: Yes
- **Type**: Admin JWT Token
- **Header**: `Authorization: Bearer YOUR_ADMIN_JWT_TOKEN`

## Query Parameters
- `area` (optional): Filter lines by area name
- `line_names_only` (optional): Return only unique line names. Set to `true` or `1` for simplified response

## Request Example

### cURL (Bash/Zsh)
```bash
# Get all lines (full details)
curl -X GET "https://dayloanapp.xesstechlink.com/admin/lines" \
  -H "Authorization: Bearer YOUR_ADMIN_JWT_TOKEN" \
  -H "Accept: application/json"

# Get only line names (simplified)
curl -X GET "https://dayloanapp.xesstechlink.com/admin/lines?line_names_only=true" \
  -H "Authorization: Bearer YOUR_ADMIN_JWT_TOKEN" \
  -H "Accept: application/json"

# Get lines filtered by area
curl -X GET "https://dayloanapp.xesstechlink.com/admin/lines?area=Mollapalayam" \
  -H "Authorization: Bearer YOUR_ADMIN_JWT_TOKEN" \
  -H "Accept: application/json"
```

### cURL (PowerShell)
```powershell
$headers = @{
    "Authorization" = "Bearer YOUR_ADMIN_JWT_TOKEN"
    "Accept" = "application/json"
}

# Get all lines
Invoke-RestMethod -Uri "http://192.168.1.3:3000/admin/lines" `
  -Method GET `
  -Headers $headers

# Get lines filtered by area
Invoke-RestMethod -Uri "http://192.168.1.3:3000/admin/lines?area=Mollapalayam" `
  -Method GET `
  -Headers $headers
```

## Success Response

### Status Code: 200 OK - Full Details (Default)

```json
{
  "status": "success",
  "message": "Lines retrieved successfully",
  "data": {
    "filters": {
      "area": null
    },
    "summary": {
      "total_lines": 8,
      "unique_line_names": 3,
      "unique_areas": 7,
      "line_names": [
        "Line 1",
        "Line 2",
        "Line 3"
      ],
      "areas": [
        "Bus Stand",
        "Fire Service",
        "Gobi",
        "Karungalpalayam",
        "Kollampalayam",
        "Mollapalayam",
        "P.S.Park",
        "VOC Park"
      ]
    },
    "lines_grouped": [
      {
        "line_name": "Line 1",
        "areas": [
          {
            "id": 9,
            "area": "VOC Park",
            "created_on": "2025-11-21T05:42:53.000Z"
          },
          {
            "id": 10,
            "area": "Bus Stand",
            "created_on": "2025-11-21T05:42:53.000Z"
          },
          {
            "id": 11,
            "area": "Karungalpalayam",
            "created_on": "2025-11-21T05:42:53.000Z"
          }
        ],
        "total_areas": 3
      },
      {
        "line_name": "Line 2",
        "areas": [
          {
            "id": 12,
            "area": "Kollampalayam",
            "created_on": "2025-11-21T05:43:29.000Z"
          },
          {
            "id": 13,
            "area": "Mollapalayam",
            "created_on": "2025-11-21T05:43:29.000Z"
          },
          {
            "id": 14,
            "area": "P.S.Park",
            "created_on": "2025-11-21T05:43:29.000Z"
          },
          {
            "id": 15,
            "area": "Fire Service",
            "created_on": "2025-11-21T05:43:29.000Z"
          }
        ],
        "total_areas": 4
      },
      {
        "line_name": "Line 3",
        "areas": [
          {
            "id": 16,
            "area": "Gobi",
            "created_on": "2025-11-21T05:43:44.000Z"
          }
        ],
        "total_areas": 1
      }
    ],
    "lines_detail": [
      {
        "id": 9,
        "area": "VOC Park",
        "line": "Line 1",
        "created_on": "2025-11-21T05:42:53.000Z"
      },
      {
        "id": 10,
        "area": "Bus Stand",
        "line": "Line 1",
        "created_on": "2025-11-21T05:42:53.000Z"
      },
      {
        "id": 11,
        "area": "Karungalpalayam",
        "line": "Line 1",
        "created_on": "2025-11-21T05:42:53.000Z"
      },
      {
        "id": 12,
        "area": "Kollampalayam",
        "line": "Line 2",
        "created_on": "2025-11-21T05:43:29.000Z"
      },
      {
        "id": 13,
        "area": "Mollapalayam",
        "line": "Line 2",
        "created_on": "2025-11-21T05:43:29.000Z"
      },
      {
        "id": 14,
        "area": "P.S.Park",
        "line": "Line 2",
        "created_on": "2025-11-21T05:43:29.000Z"
      },
      {
        "id": 15,
        "area": "Fire Service",
        "line": "Line 2",
        "created_on": "2025-11-21T05:43:29.000Z"
      },
      {
        "id": 16,
        "area": "Gobi",
        "line": "Line 3",
        "created_on": "2025-11-21T05:43:44.000Z"
      }
    ]
  }
}
```

### Status Code: 200 OK - Line Names Only (with `line_names_only=true`)

```json
{
  "status": "success",
  "message": "Line names retrieved successfully",
  "data": {
    "line_names": [
      "Line 1",
      "Line 2",
      "Line 3"
    ],
    "total_lines": 3
  }
}
```

## Response Fields

### filters
- `area`: Applied area filter (if any)

### summary
- `total_lines`: Total number of line entries
- `unique_line_names`: Number of unique line names
- `unique_areas`: Number of unique areas
- `line_names`: Array of all unique line names (sorted)
- `areas`: Array of all unique areas (sorted)

### lines_grouped (Array)
Each object contains:
- `line_name`: Name of the line
- `areas`: Array of areas assigned to this line
  - `id`: Line entry ID
  - `area`: Area name
  - `created_on`: Creation timestamp
- `total_areas`: Number of areas in this line

### lines_detail (Array)
Complete list of all line entries with:
- `id`: Line entry ID
- `area`: Area name
- `line`: Line name
- `created_on`: Creation timestamp

## Error Responses

### 401 Unauthorized - Invalid/Missing Token
```json
{
  "status": "error",
  "message": "Admin authentication required"
}
```

### 500 Internal Server Error
```json
{
  "status": "error",
  "message": "Failed to fetch lines",
  "error": "Error message details"
}
```

## Notes

1. **Company Isolation**: Admins can only view lines belonging to their own company

2. **Response Formats**:
   - **Full Details** (default): Complete information with `lines_grouped` and `lines_detail`
   - **Line Names Only** (`line_names_only=true`): Simplified response with just unique line names array

3. **Area Filtering**: Use the `area` query parameter to filter lines by a specific area

4. **Line Names Only Filter**: Use `line_names_only=true` to get only unique line names (useful for dropdowns)

5. **Sorting**: Lines are sorted by line name (ascending), then by area (ascending)

6. **Use Cases**:
   - **Line Names Only**: Get list for dropdown selection (`?line_names_only=true`)
   - **Full Details**: View all available lines for agent assignment
   - **Area Filtering**: See which areas belong to which lines
   - **Line Structure**: Understand line structure and organization

## Example Use Cases

1. **Get only line names for dropdown selection** (Recommended):
   ```bash
   GET /admin/lines?line_names_only=true
   ```
   Returns simplified array of line names perfect for dropdowns

2. **Get all lines for dropdown selection** (Full response):
   ```bash
   GET /admin/lines
   ```
   Use `summary.line_names` for dropdown options

2. **View areas in a specific line**:
   ```bash
   GET /admin/lines
   ```
   Check `lines_grouped` to see which areas belong to each line

3. **Filter by area**:
   ```bash
   GET /admin/lines?area=Mollapalayam
   ```
   Get all lines that include a specific area

4. **Get line structure**:
   ```bash
   GET /admin/lines
   ```
   Use `lines_grouped` to understand the complete line structure

