# BuyerKiosk Mobile API

## Base URL
```
https://buyerkiosk.com/api/mobile
```

## Authentication
All endpoints require an `APIKey` parameter sent via POST.

---

## Endpoints

### 1. Get Current Queue
Returns all customers currently waiting in the buy queue.

**URL:** `POST /api/mobile/currentQueue/:typeNum`

**Parameters:**
| Name | Type | Required | Description |
|------|------|----------|-------------|
| APIKey | string | Yes | Your mobile API key |
| typeNum | string | Yes | Store identifier (e.g., `pc00`, `ou00`) - passed in URL |

**Response:**
```json
[
  {
    "waitTime": "45m",
    "numContainers": 2,
    "processedContainers": 0,
    "inStore": 1,
    "customerName": "Ashley G",
    "buyerName": "John D"
  }
]
```

---

### 2. Get Completed Buys
Returns all completed buys for the current day.

**URL:** `POST /api/mobile/completedBuys/:typeNum`

**Parameters:**
| Name | Type | Required | Description |
|------|------|----------|-------------|
| APIKey | string | Yes | Your mobile API key |
| typeNum | string | Yes | Store identifier - passed in URL |

**Response:**
```json
[
  {
    "customerName": "Jane D",
    "buyerName": "John Smith",
    "numContainers": 3,
    "dailyNum": 15,
    "processTime": "12m",
    "timeCompleted": "2:30 PM"
  }
]
```

---

### 3. Get Store Page Stats
Returns store statistics for the current day.

**URL:** `POST /api/mobile/storePage/:typeNum`

**Parameters:**
| Name | Type | Required | Description |
|------|------|----------|-------------|
| APIKey | string | Yes | Your mobile API key |
| typeNum | string | Yes | Store identifier - passed in URL |

**Response:**
```json
{
  "totalBuys": 25,
  "startDelay": "5m 30s",
  "processTimeAvg": "8m 15s",
  "processPerContainer": "3m 45s",
  "inQueue": 4,
  "numCompleted": 21,
  "numBuyers": 3,
  "numSorters": 2
}
```

---

### 4. Get Buyer Stats
Returns performance statistics for each buyer working today.

**URL:** `POST /api/mobile/buyerStats/:typeNum`

**Parameters:**
| Name | Type | Required | Description |
|------|------|----------|-------------|
| APIKey | string | Yes | Your mobile API key |
| typeNum | string | Yes | Store identifier - passed in URL |

**Response:**
```json
[
  {
    "buyerName": "John. S",
    "avgProcessTime": "7m 30s",
    "avgPTC": "2m 45s",
    "numBuys": 12,
    "numBins": 28
  }
]
```

---

### 5. Get Dashboard
Returns overview data for all stores associated with the API key.

**URL:** `POST /api/mobile/dashboard`

**Parameters:**
| Name | Type | Required | Description |
|------|------|----------|-------------|
| APIKey | string | Yes | Your mobile API key |

**Response:**
```json
[
  {
    "typeNum": "pc00",
    "storeCity": "Anna",
    "storeType": 1,
    "numBuyers": 3,
    "numSorters": 2,
    "numInQueue": 4,
    "numBuysToday": 25,
    "waitTimeMinutes": 45,
    "liveFinancials": {
      "bGoal": "$500.00",
      "bCurrent": "$325.50",
      "sGoal": "$2000.00",
      "sCurrent": "$1450.00",
      "date": "2025-12-01"
    }
  }
]
```

---

## Store Types
| Value | Type |
|-------|------|
| 1 | Plato's Closet |
| 2 | Once Upon A Child |
| 3 | Style Encore |
| 4 | Clothes Mentor |
| 5 | Home Once More |

---

## Legacy Endpoint (Deprecated)

The old endpoint `POST /api/mobile.php` still works for backward compatibility but should be migrated to the new routes above.

**Legacy format:**
```
POST /api/mobile.php
Body: APIKey=XXX&store=pc00&action=currentQueue
```

**New format:**
```
POST /api/mobile/currentQueue/pc00
Body: APIKey=XXX
```

---

## Example cURL Requests

```bash
# Current Queue
curl -X POST https://buyerkiosk.com/api/mobile/currentQueue/pc00 \
  -d "APIKey=YOUR_API_KEY"

# Dashboard
curl -X POST https://buyerkiosk.com/api/mobile/dashboard \
  -d "APIKey=YOUR_API_KEY"
```

---

## Error Responses

**400 Bad Request:**
```json
{"error": "Missing APIKey parameter"}
```

**403 Forbidden:**
```json
{"error": "Invalid API key"}
```

**500 Internal Server Error:**
```json
{"error": "An internal error occurred"}
```
