{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/samva-dev/json-schema/samva-dev-conversation-schema.json",
  "title": "Conversation",
  "x-generated": "2026-10-31",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/samva-dev-openapi.json#/components/schemas/Conversation",
  "type": "object",
  "properties": {
    "id": {
      "$ref": "#/$defs/ConversationId"
    },
    "title": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "externalId": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "status": {
      "type": "string",
      "enum": [
        "active",
        "waiting",
        "resolved",
        "escalated",
        "archived"
      ]
    },
    "primaryChannel": {
      "type": "string",
      "enum": [
        "email"
      ]
    },
    "channels": {
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "email"
        ]
      }
    },
    "priority": {
      "type": "integer",
      "minimum": 0,
      "maximum": 9007199254740991
    },
    "urgency": {
      "type": "string",
      "enum": [
        "low",
        "medium",
        "high",
        "critical"
      ]
    },
    "tags": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "isTest": {
      "type": "boolean"
    },
    "messageCount": {
      "type": "integer",
      "minimum": 0,
      "maximum": 9007199254740991
    },
    "lastActivityAt": {
      "type": "string"
    },
    "createdAt": {
      "type": "string"
    },
    "description": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "parentConversationId": {
      "anyOf": [
        {
          "$ref": "#/$defs/ConversationId"
        },
        {
          "type": "null"
        }
      ]
    },
    "statusReason": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "complexity": {
      "type": "string",
      "enum": [
        "simple",
        "moderate",
        "complex"
      ]
    },
    "categories": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "metadata": {
      "anyOf": [
        {
          "$ref": "#/$defs/JsonObject"
        },
        {
          "type": "null"
        }
      ]
    },
    "context": {
      "anyOf": [
        {
          "$ref": "#/$defs/ConversationContext"
        },
        {
          "type": "null"
        }
      ]
    },
    "isInternal": {
      "type": "boolean"
    },
    "isPrivate": {
      "type": "boolean"
    },
    "contacts": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/ConversationContact"
      }
    },
    "startedAt": {
      "type": "string"
    },
    "lastHumanActivityAt": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "resolvedAt": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "archivedAt": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "resolutionType": {
      "anyOf": [
        {
          "type": "string",
          "enum": [
            "automated",
            "human_assisted",
            "escalated",
            "abandoned",
            "timeout"
          ]
        },
        {
          "type": "null"
        }
      ]
    },
    "resolutionNotes": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "updatedAt": {
      "type": "string"
    }
  },
  "required": [
    "id",
    "title",
    "externalId",
    "status",
    "primaryChannel",
    "channels",
    "priority",
    "urgency",
    "tags",
    "isTest",
    "messageCount",
    "lastActivityAt",
    "createdAt",
    "description",
    "parentConversationId",
    "statusReason",
    "complexity",
    "categories",
    "metadata",
    "context",
    "isInternal",
    "isPrivate",
    "contacts",
    "startedAt",
    "lastHumanActivityAt",
    "resolvedAt",
    "archivedAt",
    "resolutionType",
    "resolutionNotes",
    "updatedAt"
  ],
  "additionalProperties": false,
  "$defs": {
    "ContactId": {
      "type": "string",
      "pattern": "^contact_[0-9a-hjkmnp-tv-z]{16,24}$",
      "x-samva-brand": "ContactId"
    },
    "ConversationContact": {
      "type": "object",
      "properties": {
        "id": {
          "$ref": "#/$defs/ContactId"
        },
        "name": {
          "type": "string"
        },
        "displayName": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "identities": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "email",
                  "phone"
                ]
              },
              "identifier": {
                "type": "string"
              },
              "verified": {
                "type": "boolean"
              }
            },
            "required": [
              "type",
              "identifier",
              "verified"
            ],
            "additionalProperties": false
          }
        }
      },
      "required": [
        "id",
        "name",
        "displayName",
        "identities"
      ],
      "additionalProperties": false
    },
    "ConversationContext": {
      "type": "object",
      "properties": {
        "customerData": {
          "anyOf": [
            {
              "$ref": "#/$defs/UnknownRecord"
            },
            {
              "type": "null"
            }
          ]
        },
        "previousConversations": {
          "anyOf": [
            {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            {
              "type": "null"
            }
          ]
        },
        "sessionVariables": {
          "anyOf": [
            {
              "$ref": "#/$defs/UnknownRecord"
            },
            {
              "type": "null"
            }
          ]
        },
        "workflowState": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "currentStep": {
                  "anyOf": [
                    {
                      "type": "string"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "completedSteps": {
                  "anyOf": [
                    {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "pendingSteps": {
                  "anyOf": [
                    {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "workflowData": {
                  "anyOf": [
                    {
                      "$ref": "#/$defs/UnknownRecord"
                    },
                    {
                      "type": "null"
                    }
                  ]
                }
              },
              "additionalProperties": false
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "additionalProperties": false
    },
    "ConversationId": {
      "type": "string",
      "pattern": "^conv_[0-9a-hjkmnp-tv-z]{16,24}$",
      "x-samva-brand": "ConversationId"
    },
    "JsonObject": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/JsonValue"
      }
    },
    "JsonValue": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "number"
        },
        {
          "type": "boolean"
        },
        {
          "type": "null"
        },
        {
          "type": "array",
          "items": {
            "$ref": "#/$defs/JsonValue"
          }
        },
        {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/JsonValue"
          }
        }
      ]
    },
    "UnknownRecord": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/JsonValue"
      }
    }
  }
}