{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/callidus-legal-ai/json-schema/callidus-legal-ai-detect-matter-response-schema.json",
  "title": "DetectMatterResponse",
  "description": "The matter the open thread belongs to, if it can be established.",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/callidus-legal-ai-addin-outlook-api-openapi.yml#/components/schemas/DetectMatterResponse",
  "properties": {
    "matter": {
      "anyOf": [
        {
          "$ref": "#/$defs/MatterSummary"
        },
        {
          "type": "null"
        }
      ]
    },
    "source": {
      "type": "string",
      "title": "Source",
      "description": "How the matter was established: 'folder' when a connected Outlook folder answered it, 'none' when nothing matched and the pane must ask the user to choose, 'ambiguous' when the folder is linked to several matters and the user must pick one of ``candidates``."
    },
    "counts": {
      "$ref": "#/$defs/ContextCounts",
      "default": {
        "thread_messages": 0,
        "matter_files": 0,
        "matter_emails": 0
      }
    },
    "has_matters": {
      "type": "boolean",
      "title": "Has Matters",
      "description": "Whether the caller can view any matter at all. False lets the pane offer Create Matter instead of a picker with nothing in it. Only meaningful when no matter was detected; a detected matter implies True.",
      "default": true
    },
    "candidates": {
      "items": {
        "$ref": "#/$defs/MatterSummary"
      },
      "type": "array",
      "title": "Candidates",
      "description": "When source is 'ambiguous': the matters the thread could belong to, in the order the picker should list them. Empty otherwise."
    },
    "candidate_source": {
      "type": "string",
      "title": "Candidate Source",
      "description": "Which lookup produced the match — ``candidates`` when ambiguous, ``matter`` otherwise: 'folder' when a connected Outlook folder answered, 'thread' when this thread was already synced into the matter(s). The pane words the pinned-group heading and the card's 'Detected from …' line from this, so neither can claim a folder connection that does not exist. Defaults to 'folder', which is what every caller assumed before this field existed.",
      "default": "folder"
    }
  },
  "type": "object",
  "required": [
    "source"
  ],
  "$defs": {
    "ContextCounts": {
      "properties": {
        "thread_messages": {
          "type": "integer",
          "title": "Thread Messages",
          "default": 0
        },
        "matter_files": {
          "type": "integer",
          "title": "Matter Files",
          "default": 0
        },
        "matter_emails": {
          "type": "integer",
          "title": "Matter Emails",
          "default": 0
        }
      },
      "type": "object",
      "title": "ContextCounts",
      "description": "What the pane's three context checkboxes report.\n\n``thread_messages`` comes from the conversation as Graph reports it, which\nis the same thread the draft is built from. The pane's own parse of the\nquoted block is used only when Graph cannot answer: it cannot see the\nmessage being replied to and recognises only Outlook's ``From:`` header\nformat, so it reads low against a chain quoted in another client's style."
    },
    "MatterSummary": {
      "properties": {
        "id": {
          "type": "string",
          "title": "Id"
        },
        "name": {
          "type": "string",
          "title": "Name"
        },
        "client": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Client",
          "description": "Client display name. None when the matter has no client attached."
        },
        "role": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Role",
          "description": "Party role, e.g. Defendant/Respondent."
        },
        "practice_area": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Practice Area",
          "description": "Matter type, e.g. Employment Law."
        }
      },
      "type": "object",
      "required": [
        "id",
        "name"
      ],
      "title": "MatterSummary",
      "description": "A matter as the add-in's matter card renders it."
    }
  }
}