{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/last-price-ai/json-schema/last-price-ai-customer-overview-schema.json",
  "title": "CustomerOverview",
  "description": "Answer of `GET /api/customers/{customerId}/overview`. Each section is\nnull when it could not be read this time, and named in `unavailable`.\n",
  "x-generated": "2026-11-15",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/last-price-ai-openapi.json#/components/schemas/CustomerOverview",
  "type": "object",
  "required": [
    "released",
    "customer",
    "as_of",
    "health",
    "unavailable"
  ],
  "properties": {
    "released": {
      "type": "boolean",
      "enum": [
        true
      ]
    },
    "customer": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid"
        },
        "external_id": {
          "type": [
            "string",
            "null"
          ]
        },
        "name": {
          "type": "string"
        },
        "created_at": {
          "type": "string",
          "format": "date-time"
        }
      }
    },
    "as_of": {
      "type": "string",
      "format": "date-time"
    },
    "revenue": {
      "type": [
        "array",
        "null"
      ],
      "description": "Invoiced amounts per currency, drafts and cancelled invoices left out.",
      "items": {
        "$ref": "#/$defs/CustomerPeriodMoney"
      }
    },
    "invoices": {
      "type": [
        "object",
        "null"
      ],
      "properties": {
        "total": {
          "type": "integer"
        },
        "draft": {
          "type": "integer"
        },
        "paid": {
          "type": "integer"
        },
        "outstanding": {
          "type": "object",
          "properties": {
            "count": {
              "type": "integer"
            },
            "amounts": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/CustomerMoney"
              }
            }
          }
        },
        "overdue": {
          "type": "object",
          "properties": {
            "count": {
              "type": "integer"
            },
            "amounts": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/CustomerMoney"
              }
            },
            "oldest_due_date": {
              "type": [
                "string",
                "null"
              ],
              "format": "date-time"
            }
          }
        },
        "last_invoice_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        }
      }
    },
    "payments": {
      "type": [
        "object",
        "null"
      ],
      "properties": {
        "total": {
          "type": "integer"
        },
        "completed": {
          "type": "integer"
        },
        "pending": {
          "type": "integer"
        },
        "refunded": {
          "type": "integer"
        },
        "refunded_last_90_days": {
          "type": "integer"
        },
        "completed_last_90_days": {
          "type": "integer"
        },
        "collected": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/CustomerPeriodMoney"
          }
        },
        "last_payment_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        }
      }
    },
    "credit": {
      "type": [
        "object",
        "null"
      ],
      "properties": {
        "bundles": {
          "type": "integer"
        },
        "bundles_available": {
          "type": "integer"
        },
        "available": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/CustomerMoney"
          }
        },
        "expiring_within_30_days": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/CustomerMoney"
          }
        }
      }
    },
    "costs": {
      "type": [
        "object",
        "null"
      ],
      "properties": {
        "total": {
          "type": "integer"
        },
        "amounts": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/CustomerPeriodMoney"
          }
        },
        "last_cost_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        }
      }
    },
    "margin": {
      "type": [
        "array",
        "null"
      ],
      "description": "Billed revenue less cost, per currency, lifetime and the last 90 days.",
      "items": {
        "type": "object",
        "properties": {
          "currency": {
            "type": "string"
          },
          "revenue": {
            "type": "number"
          },
          "cost": {
            "type": "number"
          },
          "margin": {
            "type": "number"
          },
          "margin_pct": {
            "type": [
              "number",
              "null"
            ]
          },
          "last_90_days": {
            "type": "object",
            "properties": {
              "revenue": {
                "type": "number"
              },
              "cost": {
                "type": "number"
              },
              "margin": {
                "type": "number"
              },
              "margin_pct": {
                "type": [
                  "number",
                  "null"
                ]
              }
            }
          }
        }
      }
    },
    "orders": {
      "type": [
        "object",
        "null"
      ],
      "properties": {
        "total": {
          "type": "integer"
        },
        "by_status": {
          "type": "object",
          "additionalProperties": {
            "type": "integer"
          }
        },
        "amounts": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/CustomerMoney"
          }
        },
        "last_order_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        }
      }
    },
    "contacts": {
      "type": [
        "object",
        "null"
      ],
      "properties": {
        "count": {
          "type": "integer"
        }
      }
    },
    "disputes": {
      "type": [
        "object",
        "null"
      ],
      "properties": {
        "open": {
          "type": "integer"
        }
      }
    },
    "usage": {
      "type": [
        "object",
        "null"
      ],
      "properties": {
        "window_days": {
          "type": "integer"
        },
        "daily": {
          "type": "array",
          "description": "One row per UTC day, oldest first, zero on a day with nothing.",
          "items": {
            "type": "object",
            "properties": {
              "date": {
                "type": "string",
                "format": "date"
              },
              "signals": {
                "type": "integer"
              },
              "quotes": {
                "type": "integer"
              }
            }
          }
        },
        "trend": {
          "type": "object",
          "properties": {
            "last_30_days": {
              "type": "integer"
            },
            "previous_30_days": {
              "type": "integer"
            },
            "change_pct": {
              "type": [
                "number",
                "null"
              ]
            },
            "direction": {
              "type": "string",
              "enum": [
                "up",
                "down",
                "flat",
                "new",
                "none"
              ]
            }
          }
        },
        "signals_total": {
          "type": "integer"
        },
        "quotes_total": {
          "type": "integer"
        },
        "top_events": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "event_type": {
                "type": "string"
              },
              "count": {
                "type": "integer"
              }
            }
          }
        },
        "last_signal_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "last_quote_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        }
      }
    },
    "last_activity": {
      "type": [
        "object",
        "null"
      ],
      "properties": {
        "at": {
          "type": "string",
          "format": "date-time"
        },
        "kind": {
          "type": "string",
          "enum": [
            "invoice",
            "payment",
            "order",
            "cost",
            "usage_signal",
            "quote",
            "negotiation"
          ]
        }
      }
    },
    "agents": {
      "type": [
        "array",
        "null"
      ],
      "items": {
        "$ref": "#/$defs/CustomerLinkedAgent"
      }
    },
    "work_value": {
      "type": [
        "object",
        "null"
      ],
      "description": "What the agents' work for this customer would have cost done by a\nperson: this customer's usage signals, counted per agent, times the\nUSD value per occurrence each agent's Value Receipt sets for that\nsignal. Only signals with a value count; `signals` is empty when\nnone has one.\n",
      "required": [
        "total_usd",
        "occurrences",
        "signals"
      ],
      "properties": {
        "total_usd": {
          "type": "number"
        },
        "occurrences": {
          "type": "integer",
          "description": "Occurrences of valued signals."
        },
        "signals": {
          "type": "array",
          "description": "Largest first, at most 20.",
          "maxItems": 20,
          "items": {
            "type": "object",
            "required": [
              "agent_id",
              "agent_name",
              "event_type",
              "display_name",
              "count",
              "value_each_usd",
              "value_usd"
            ],
            "properties": {
              "agent_id": {
                "type": "string",
                "format": "uuid"
              },
              "agent_name": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "event_type": {
                "type": "string"
              },
              "display_name": {
                "type": "string",
                "description": "The signal's name as the agent's Value Receipt shows it."
              },
              "count": {
                "type": "integer"
              },
              "value_each_usd": {
                "type": "number"
              },
              "value_usd": {
                "type": "number"
              }
            }
          }
        }
      }
    },
    "health": {
      "type": "object",
      "required": [
        "status",
        "score",
        "reasons"
      ],
      "properties": {
        "status": {
          "type": "string",
          "enum": [
            "healthy",
            "watch",
            "at_risk",
            "new",
            "no_activity"
          ]
        },
        "score": {
          "type": "integer",
          "minimum": 0,
          "maximum": 100,
          "description": "Health score, higher is healthier. It always sits in the band of\n`status`: `at_risk` 0 to 49, `watch`, `new` and `no_activity` 50\nto 74, `healthy` 75 to 100.\n"
        },
        "reasons": {
          "type": "array",
          "description": "What the status rests on, each with whether it helps or hurts.",
          "items": {
            "type": "object",
            "required": [
              "code",
              "signal",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "signal": {
                "type": "string",
                "enum": [
                  "good",
                  "warn",
                  "bad",
                  "info"
                ]
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      }
    },
    "unavailable": {
      "type": "array",
      "items": {
        "type": "string"
      }
    }
  },
  "$defs": {
    "CustomerLinkedAgent": {
      "type": "object",
      "required": [
        "id",
        "name",
        "status",
        "sources",
        "last_seen_at"
      ],
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid"
        },
        "name": {
          "type": [
            "string",
            "null"
          ]
        },
        "status": {
          "type": [
            "string",
            "null"
          ]
        },
        "sources": {
          "type": "array",
          "description": "Where the link was seen.",
          "items": {
            "type": "string",
            "enum": [
              "orders",
              "costs",
              "signals",
              "quotes"
            ]
          }
        },
        "last_seen_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        }
      }
    },
    "CustomerMoney": {
      "type": "object",
      "description": "An amount in one currency. Never summed across currencies.",
      "required": [
        "currency",
        "amount"
      ],
      "properties": {
        "currency": {
          "type": "string"
        },
        "amount": {
          "type": "number"
        }
      }
    },
    "CustomerPeriodMoney": {
      "type": "object",
      "required": [
        "currency",
        "lifetime",
        "last_30_days",
        "last_90_days"
      ],
      "properties": {
        "currency": {
          "type": "string"
        },
        "lifetime": {
          "type": "number"
        },
        "last_30_days": {
          "type": "number"
        },
        "last_90_days": {
          "type": "number"
        }
      }
    }
  }
}