{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://api.schematichq.com/schemas/company",
  "title": "Schematic Company",
  "description": "A company (customer organization) record in Schematic, representing a billable entity with features, plans, and entitlements.",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "description": "Unique Schematic company identifier."
    },
    "name": {
      "type": "string",
      "description": "Display name of the company."
    },
    "keys": {
      "type": "object",
      "description": "External system keys used to identify the company (e.g., Stripe customer ID, Salesforce account ID).",
      "additionalProperties": { "type": "string" }
    },
    "traits": {
      "type": "object",
      "description": "Custom metadata attributes for the company.",
      "additionalProperties": true
    },
    "plan": {
      "$ref": "#/$defs/PlanRef",
      "description": "The active subscription plan for the company."
    },
    "entityTraits": {
      "type": "array",
      "description": "Trait values associated with this company.",
      "items": { "$ref": "#/$defs/EntityTrait" }
    },
    "createdAt": {
      "type": "string",
      "format": "date-time",
      "description": "ISO 8601 timestamp when the company was created."
    },
    "updatedAt": {
      "type": "string",
      "format": "date-time",
      "description": "ISO 8601 timestamp when the company was last updated."
    },
    "lastSeenAt": {
      "type": "string",
      "format": "date-time",
      "description": "ISO 8601 timestamp of the most recent activity for this company."
    },
    "userCount": {
      "type": "integer",
      "description": "Number of users associated with this company."
    }
  },
  "required": ["id", "name"],
  "$defs": {
    "PlanRef": {
      "type": "object",
      "properties": {
        "id": { "type": "string" },
        "name": { "type": "string" }
      }
    },
    "EntityTrait": {
      "type": "object",
      "properties": {
        "traitDefinitionId": { "type": "string" },
        "value": {}
      }
    }
  }
}
