{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/asap-cool/json-schema/asap-cool-deal-stats-view-schema.json",
  "title": "DealStatsView",
  "description": "Response of `GET /v1/crm/stats`.",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/asap-cool-crm-api-openapi.yml#/components/schemas/DealStatsView",
  "type": "object",
  "required": [
    "series",
    "won_count",
    "lost_count",
    "open_count",
    "open_cents",
    "by_source"
  ],
  "properties": {
    "by_source": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/DealSourceView"
      },
      "description": "Deals created in the window per origin, largest first."
    },
    "lost_count": {
      "type": "integer",
      "format": "int64",
      "description": "Deals lost in the window."
    },
    "median_cycle_days": {
      "type": [
        "integer",
        "null"
      ],
      "format": "int64",
      "description": "Median days from creation to win over the deals won in the window."
    },
    "open_cents": {
      "type": "integer",
      "format": "int64",
      "description": "Expected amount of the open deals now, **in cents** (window-invariant)."
    },
    "open_count": {
      "type": "integer",
      "format": "int64",
      "description": "Deals still open now (window-invariant)."
    },
    "series": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/DealStatsPointView"
      },
      "description": "Month series over the window, gap-filled, oldest first."
    },
    "win_rate_bp": {
      "type": [
        "integer",
        "null"
      ],
      "format": "int64",
      "description": "`won / (won + lost)` in basis points, `null` when nothing closed."
    },
    "won_count": {
      "type": "integer",
      "format": "int64",
      "description": "Deals won in the window."
    }
  },
  "$defs": {
    "DealSourceView": {
      "type": "object",
      "description": "Deals created in the window from one origin.",
      "required": [
        "source",
        "count",
        "won_count"
      ],
      "properties": {
        "count": {
          "type": "integer",
          "format": "int64",
          "description": "Deals created from that source."
        },
        "source": {
          "type": "string",
          "description": "`manual`, `sourcing`, `outreach` or `chat`."
        },
        "won_count": {
          "type": "integer",
          "format": "int64",
          "description": "Of which won."
        }
      }
    },
    "DealStatsPointView": {
      "type": "object",
      "description": "One month of deal flow.",
      "required": [
        "period",
        "created_count",
        "won_count",
        "won_cents",
        "lost_count"
      ],
      "properties": {
        "created_count": {
          "type": "integer",
          "format": "int64",
          "description": "Deals created that month."
        },
        "lost_count": {
          "type": "integer",
          "format": "int64",
          "description": "Deals lost that month."
        },
        "period": {
          "type": "string",
          "description": "Month, `YYYY-MM`."
        },
        "won_cents": {
          "type": "integer",
          "format": "int64",
          "description": "Expected amount of the deals won that month, **in cents**."
        },
        "won_count": {
          "type": "integer",
          "format": "int64",
          "description": "Deals won that month."
        }
      }
    }
  }
}