# Agent API: Check Today's Check-In Status

## Endpoint
`GET /agent/check-today-checkin`

## Description
Checks if the authenticated agent has checked in today. Returns check-in status, check-in/check-out details, and duration if checked in.

## Authentication
Requires agent authentication via Bearer token (JWT or auth_token).

## Query Parameters
None required. Uses authenticated agent's ID automatically.

## cURL Examples

### Check Today's Check-In Status
```bash
curl -X GET "https://dayloanapp.xesstechlink.com/agent/check-today-checkin" \
  -H "accept: application/json" \
  -H "authorization: Bearer YOUR_AGENT_JWT_TOKEN"
```

## Response Format

### Success Response (200 OK) - Agent Has Checked In Today
```json
{
  "status": "success",
  "message": "Today's check-in status retrieved",
  "data": {
    "agent_id": 3,
    "agent_name": "Arshaf",
    "date": "2025-12-13",
    "has_checked_in": true,
    "has_checked_out": false,
    "is_currently_checked_in": true,
    "check_in": {
      "id": 123,
      "time": "2025-12-13T09:15:00.000Z",
      "latitude": 11.34567890,
      "longitude": 77.71234567,
      "address": "123 Main Street, Erode",
      "remark": "Morning check-in"
    },
    "check_out": null,
    "duration_minutes": 125
  }
}
```

### Success Response (200 OK) - Agent Has Checked In and Out Today
```json
{
  "status": "success",
  "message": "Today's check-in status retrieved",
  "data": {
    "agent_id": 3,
    "agent_name": "Arshaf",
    "date": "2025-12-13",
    "has_checked_in": true,
    "has_checked_out": true,
    "is_currently_checked_in": false,
    "check_in": {
      "id": 123,
      "time": "2025-12-13T09:15:00.000Z",
      "latitude": 11.34567890,
      "longitude": 77.71234567,
      "address": "123 Main Street, Erode",
      "remark": "Morning check-in"
    },
    "check_out": {
      "id": 124,
      "time": "2025-12-13T18:30:00.000Z",
      "latitude": 11.34567890,
      "longitude": 77.71234567,
      "address": "123 Main Street, Erode",
      "remark": "Evening check-out"
    },
    "duration_minutes": 555
  }
}
```

### Success Response (200 OK) - Agent Has Not Checked In Today
```json
{
  "status": "success",
  "message": "Today's check-in status retrieved",
  "data": {
    "agent_id": 3,
    "agent_name": "Arshaf",
    "date": "2025-12-13",
    "has_checked_in": false,
    "has_checked_out": false,
    "is_currently_checked_in": false,
    "check_in": null,
    "check_out": null,
    "duration_minutes": null
  }
}
```

### Error Response (401 Unauthorized)
```json
{
  "status": "error",
  "message": "Not authenticated"
}
```

### Error Response (404 Not Found)
```json
{
  "status": "error",
  "message": "Agent not found"
}
```

### Error Response (500 Internal Server Error)
```json
{
  "status": "error",
  "message": "Failed to check today's check-in status",
  "error": "Error message details"
}
```

## Response Fields

### Data Object Fields
- `agent_id`: Agent's unique identifier
- `agent_name`: Agent's name
- `date`: Today's date (YYYY-MM-DD format)
- `has_checked_in`: Boolean indicating if agent checked in today
- `has_checked_out`: Boolean indicating if agent checked out today
- `is_currently_checked_in`: Boolean indicating if agent is currently checked in (checked in but not checked out)
- `check_in`: Check-in details object (null if not checked in)
  - `id`: Check-in record ID
  - `time`: Check-in timestamp
  - `latitude`: Check-in latitude
  - `longitude`: Check-in longitude
  - `address`: Check-in address
  - `remark`: Check-in remark/notes
- `check_out`: Check-out details object (null if not checked out)
  - `id`: Check-out record ID
  - `time`: Check-out timestamp
  - `latitude`: Check-out latitude
  - `longitude`: Check-out longitude
  - `address`: Check-out address
  - `remark`: Check-out remark/notes
- `duration_minutes`: Duration in minutes (from check-in to check-out, or current time if still checked in). Null if not checked in.

## Notes

1. **Authentication**: Replace `YOUR_AGENT_JWT_TOKEN` with a valid agent JWT token obtained from `/verify_otp` or login endpoint.

2. **Date**: The API automatically uses today's date. No date parameter is needed.

3. **Check-In Tracking**: 
   - Check-ins are tracked in `agent_location_tracking` table with `activity_type = 'check_in'`
   - Check-outs are tracked with `activity_type = 'check_out'`
   - Only today's records are considered

4. **Status Logic**:
   - `has_checked_in = true`: Agent has at least one check-in record today
   - `has_checked_out = true`: Agent has checked out today (after check-in)
   - `is_currently_checked_in = true`: Agent checked in today but hasn't checked out yet

5. **Duration Calculation**:
   - If checked in but not checked out: Duration from check-in time to current time
   - If checked in and checked out: Duration from check-in to check-out time
   - If not checked in: Duration is null

6. **Multiple Check-Ins**: If an agent has multiple check-ins today, only the latest one is returned.

## Use Cases

1. **Check if agent needs to check in**: 
   - Use `has_checked_in` to determine if agent should check in
   - Show check-in button if `has_checked_in = false`

2. **Show current status**:
   - Use `is_currently_checked_in` to show if agent is currently working
   - Display duration if checked in

3. **Display check-in/check-out times**:
   - Show check-in time and location
   - Show check-out time and location if available

## Example with Real Server URL

```bash
curl -X GET "https://dayloanapp.xesstechlink.com/agent/check-today-checkin" \
  -H "accept: application/json" \
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
```

## Related Endpoints

- `GET /agent/check-times` - Get agent's scheduled check-in/check-out times
- `POST /track_location` - Track location (can be used for check-in/check-out)

