{
  "openapi": "3.1.0",
  "info": {
    "title": "Frank Martinez — Collaboration Match API",
    "version": "1.0.0",
    "description": "Sessioned interview API for Frank's AI collaboration match system (Ixchel). Prefer this over scraping the terminal UI. See also /llms.txt and docs/MATCH_MCP_PLAN.md."
  },
  "servers": [
    { "url": "https://frankmartinez.ai" }
  ],
  "paths": {
    "/api/v1/match/sessions": {
      "post": {
        "operationId": "startMatchSession",
        "summary": "Start a match interview session",
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "userId": {
                    "type": "string",
                    "description": "Optional anonymous user id for S3 memory persistence"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Session created with first question",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/StartSessionResponse" }
              }
            }
          }
        }
      }
    },
    "/api/v1/match/sessions/{sessionId}/answers": {
      "post": {
        "operationId": "answerMatchSession",
        "summary": "Submit an answer to the current interview question",
        "parameters": [
          {
            "name": "sessionId",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["answer"],
                "properties": {
                  "answer": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Next question or completed profile",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/AnswerSessionResponse" }
              }
            }
          },
          "404": { "description": "Session not found" },
          "409": { "description": "Session already complete" }
        }
      }
    },
    "/api/v1/match/sessions/{sessionId}/profile": {
      "get": {
        "operationId": "getMatchSessionProfile",
        "summary": "Get profile for a session (null until interview complete)",
        "parameters": [
          {
            "name": "sessionId",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": {
            "description": "Profile status",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ProfileResponse" }
              }
            }
          },
          "404": { "description": "Session not found" }
        }
      }
    },
    "/api/v1/match/sessions/{sessionId}/contact": {
      "post": {
        "operationId": "submitMatchSessionContact",
        "summary": "Email match profile and sync CRM lead",
        "parameters": [
          {
            "name": "sessionId",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["email"],
                "properties": {
                  "email": { "type": "string", "format": "email" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Email sent",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": { "type": "boolean" },
                    "email": { "type": "string" }
                  }
                }
              }
            }
          },
          "409": { "description": "Profile not ready" },
          "502": { "description": "Email send failed" }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Question": {
        "type": "object",
        "properties": {
          "index": { "type": "integer" },
          "key": { "type": "string" },
          "prompt": { "type": "string" }
        }
      },
      "CollaborationMatchProfile": {
        "type": "object",
        "properties": {
          "handle": { "type": "string" },
          "hard_problems": { "type": "array", "items": { "type": "string" } },
          "skills": { "type": "array", "items": { "type": "string" } },
          "experience": { "type": "array", "items": { "type": "string" } },
          "meetings": { "type": "array", "items": { "type": "string" } },
          "work_styles": { "type": "array", "items": { "type": "string" } },
          "match_score": { "type": "number" },
          "rationale": { "type": "string" }
        }
      },
      "StartSessionResponse": {
        "type": "object",
        "properties": {
          "sessionId": { "type": "string" },
          "matchId": { "type": "string" },
          "status": { "type": "string", "enum": ["in_progress"] },
          "question": { "$ref": "#/components/schemas/Question" },
          "questionsTotal": { "type": "integer" }
        }
      },
      "AnswerSessionResponse": {
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "sessionId": { "type": "string" },
              "status": { "type": "string", "enum": ["in_progress"] },
              "complete": { "type": "boolean", "enum": [false] },
              "question": { "$ref": "#/components/schemas/Question" },
              "answeredCount": { "type": "integer" },
              "questionsTotal": { "type": "integer" }
            }
          },
          {
            "type": "object",
            "properties": {
              "sessionId": { "type": "string" },
              "status": { "type": "string", "enum": ["completed"] },
              "complete": { "type": "boolean", "enum": [true] },
              "profile": { "$ref": "#/components/schemas/CollaborationMatchProfile" },
              "strongMatch": { "type": "boolean" },
              "questionsTotal": { "type": "integer" }
            }
          }
        ]
      },
      "ProfileResponse": {
        "type": "object",
        "properties": {
          "sessionId": { "type": "string" },
          "status": { "type": "string" },
          "profile": {
            "oneOf": [
              { "$ref": "#/components/schemas/CollaborationMatchProfile" },
              { "type": "null" }
            ]
          },
          "strongMatch": { "type": "boolean" },
          "contactEmail": { "type": "string" }
        }
      }
    }
  }
}
