{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/wasync-app/json-schema/wasync-app-agent-report-response-schema.json",
  "title": "AgentReportResponse",
  "x-generated": "2026-11-28",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/wasync-app-openapi.json#/components/schemas/AgentReportResponse",
  "type": "object",
  "required": [
    "range",
    "totals",
    "agents",
    "attributionSince"
  ],
  "properties": {
    "range": {
      "type": "object",
      "required": [
        "from",
        "to"
      ],
      "properties": {
        "from": {
          "type": "string",
          "format": "date"
        },
        "to": {
          "type": "string",
          "format": "date"
        }
      }
    },
    "totals": {
      "type": "object",
      "required": [
        "conversations",
        "repliesSent",
        "customerTurns",
        "answeredTurns",
        "medianFirstResponseSec"
      ],
      "properties": {
        "conversations": {
          "type": "integer",
          "description": "Distinct customers who wrote in the range."
        },
        "repliesSent": {
          "type": "integer",
          "description": "All human replies in the range (the sum of `agents[].repliesSent`)."
        },
        "customerTurns": {
          "type": "integer",
          "description": "Customer turns that started in the range (consecutive customer messages count once)."
        },
        "answeredTurns": {
          "type": "integer",
          "description": "Of those, turns a person answered."
        },
        "medianFirstResponseSec": {
          "type": [
            "integer",
            "null"
          ]
        }
      }
    },
    "agents": {
      "type": "array",
      "description": "Most replies first; the unattributed row (if any) last.",
      "items": {
        "$ref": "#/$defs/AgentReportRow"
      }
    },
    "attributionSince": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time",
      "description": "When employee attribution started on this account. Replies before it are in the unattributed row."
    }
  },
  "$defs": {
    "AgentReportRow": {
      "type": "object",
      "required": [
        "userId",
        "name",
        "unattributed",
        "repliesSent",
        "conversations",
        "medianFirstResponseSec"
      ],
      "properties": {
        "userId": {
          "type": [
            "string",
            "null"
          ],
          "description": "Bitrix24 user id; null on the unattributed row."
        },
        "name": {
          "type": [
            "string",
            "null"
          ]
        },
        "unattributed": {
          "type": "boolean",
          "description": "True on the single row for replies written by a person but not linked to an employee (sent before attribution started, or typed on the phone)."
        },
        "repliesSent": {
          "type": "integer",
          "description": "Outgoing messages this person wrote in the range (no automated messages, no internal notes, no failed sends; 1:1 chats only)."
        },
        "conversations": {
          "type": "integer",
          "description": "Distinct customers this person replied to in the range."
        },
        "medianFirstResponseSec": {
          "type": [
            "integer",
            "null"
          ],
          "description": "Median seconds from a customer's first unanswered message to this person's reply, over the turns they answered first. Automated replies do not stop the clock. Null when they answered no turn that started in the range."
        }
      }
    }
  }
}