{
  "openapi": "3.1.0",
  "info": {
    "title": "EQIQs Compatibility API",
    "version": "2.3.0",
    "description": "Psychometric compatibility scoring across 21 frameworks (engine v2.0.1 scores up to 21 weighted dimensions, using only the ones your input supports). Auth via x-api-key. Idempotency-Key header is supported on all POST endpoints.",
    "contact": {
      "name": "EQIQs Support",
      "email": "BD@EQIQs.com",
      "url": "https://eqiqs.com/compatibility-api"
    },
    "license": {
      "name": "Commercial"
    }
  },
  "servers": [
    {
      "url": "https://adgmsnwjynqkhawhioil.supabase.co/functions/v1/partner-api",
      "description": "Production"
    }
  ],
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key"
      }
    },
    "schemas": {
      "Person": {
        "type": "object",
        "required": [
          "date_of_birth"
        ],
        "properties": {
          "date_of_birth": {
            "type": "string",
            "format": "date",
            "example": "1990-03-15"
          },
          "mbti_type": {
            "type": "string",
            "enum": [
              "ISTJ",
              "ISFJ",
              "INFJ",
              "INTJ",
              "ISTP",
              "ISFP",
              "INFP",
              "INTP",
              "ESTP",
              "ESFP",
              "ENFP",
              "ENTP",
              "ESTJ",
              "ESFJ",
              "ENFJ",
              "ENTJ"
            ]
          },
          "enneagram_type": {
            "type": "string",
            "example": "4w5"
          },
          "disc_type": {
            "type": "string",
            "enum": [
              "D",
              "I",
              "S",
              "C",
              "DI",
              "DC",
              "ID",
              "IS",
              "SI",
              "SC",
              "CS",
              "CD"
            ]
          },
          "attachment_style": {
            "type": "string",
            "enum": [
              "secure",
              "anxious",
              "avoidant",
              "fearful-avoidant"
            ]
          },
          "communication_style": {
            "type": "string",
            "enum": [
              "direct",
              "diplomatic",
              "analytical",
              "expressive"
            ]
          },
          "conflict_style": {
            "type": "string",
            "enum": [
              "competing",
              "collaborating",
              "compromising",
              "avoiding",
              "accommodating"
            ]
          },
          "love_language": {
            "type": "string",
            "enum": [
              "words",
              "acts",
              "gifts",
              "time",
              "touch"
            ]
          },
          "temperament": {
            "type": "string",
            "enum": [
              "sanguine",
              "choleric",
              "melancholic",
              "phlegmatic"
            ]
          },
          "riasec_type": {
            "type": "string",
            "enum": [
              "R",
              "I",
              "A",
              "S",
              "E",
              "C"
            ]
          },
          "cognitive_style": {
            "type": "string",
            "enum": [
              "analytical",
              "intuitive",
              "innovative",
              "practical"
            ]
          },
          "leadership_style": {
            "type": "string",
            "enum": [
              "directive",
              "coaching",
              "delegative",
              "transformational",
              "servant",
              "visionary"
            ]
          },
          "work_values": {
            "type": "string",
            "enum": [
              "achievement",
              "benevolence",
              "self-direction",
              "stimulation",
              "security",
              "conformity"
            ]
          },
          "career_anchor": {
            "type": "string",
            "enum": [
              "technical",
              "managerial",
              "autonomy",
              "security",
              "entrepreneurial",
              "service",
              "challenge",
              "lifestyle"
            ]
          },
          "values_ethics": {
            "type": "string",
            "enum": [
              "integrity",
              "fairness",
              "innovation",
              "tradition",
              "growth",
              "service"
            ]
          },
          "neuro_blueprint_type": {
            "type": "string"
          },
          "eq_score": {
            "type": "number",
            "minimum": 0,
            "maximum": 100
          },
          "conscientiousness_score": {
            "type": "number",
            "minimum": 0,
            "maximum": 100
          },
          "cognitive_aptitude_score": {
            "type": "number",
            "minimum": 0,
            "maximum": 100
          },
          "big_five_openness": {
            "type": "number",
            "minimum": 0,
            "maximum": 100
          },
          "big_five_conscientiousness": {
            "type": "number",
            "minimum": 0,
            "maximum": 100
          },
          "big_five_extraversion": {
            "type": "number",
            "minimum": 0,
            "maximum": 100
          },
          "big_five_agreeableness": {
            "type": "number",
            "minimum": 0,
            "maximum": 100
          },
          "big_five_neuroticism": {
            "type": "number",
            "minimum": 0,
            "maximum": 100
          }
        }
      },
      "CompatibilityResponse": {
        "type": "object",
        "properties": {
          "overall_score": {
            "type": ["integer", "null"],
            "description": "Null below three shared eligible frameworks.",
            "minimum": 0,
            "maximum": 100
          },
          "confidence": {
            "type": "string",
            "enum": [
              "low",
              "medium",
              "high"
            ],
            "deprecated": true,
            "description": "Deprecated qualitative band, retained for backward compatibility. Use frameworks_covered / dimensions_used to judge data coverage."
          },
          "confidence_pct": {
            "type": "integer",
            "deprecated": true,
            "description": "Deprecated. Use frameworks_covered instead."
          },
          "frameworks_covered": {
            "type": "integer",
            "description": "How many of the 21 frameworks had data on both people and contributed to the score."
          },
          "frameworks_total": {
            "type": "integer",
            "description": "Total frameworks in the battery (21)."
          },
          "insufficient_data": {
            "type": "boolean",
            "description": "True when fewer than 3 shared eligible frameworks were available; overall_score is null."
          },
          "subscores": {
            "type": "object",
            "additionalProperties": true
          },
          "insights": {
            "type": "object",
            "additionalProperties": true
          },
          "context": {
            "type": "string"
          },
          "engine_version": {
            "type": "string"
          },
          "dimensions_used": {
            "type": "integer"
          },
          "dimensions_total": {
            "type": "integer"
          },
          "computed_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  },
  "security": [
    {
      "ApiKeyAuth": []
    }
  ],
  "paths": {
    "/compatibility": {
      "post": {
        "summary": "Score compatibility between two people",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "person_a",
                  "person_b"
                ],
                "properties": {
                  "person_a": {
                    "$ref": "#/components/schemas/Person"
                  },
                  "person_b": {
                    "$ref": "#/components/schemas/Person"
                  },
                  "context": {
                    "type": "string",
                    "enum": [
                      "romantic",
                      "business",
                      "friendship",
                      "coparenting"
                    ],
                    "default": "romantic"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CompatibilityResponse"
                }
              }
            }
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Auth error"
          },
          "429": {
            "description": "Rate or monthly limit exceeded"
          }
        }
      }
    },
    "/compatibility/batch": {
      "post": {
        "summary": "Score up to 10 pairs in one call",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "pairs"
                ],
                "properties": {
                  "pairs": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 10,
                    "items": {
                      "type": "object",
                      "required": [
                        "person_a",
                        "person_b"
                      ],
                      "properties": {
                        "person_a": {
                          "$ref": "#/components/schemas/Person"
                        },
                        "person_b": {
                          "$ref": "#/components/schemas/Person"
                        },
                        "context": {
                          "type": "string",
                          "enum": [
                            "romantic",
                            "business",
                            "friendship",
                            "coparenting"
                          ],
                          "default": "romantic"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "results": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/CompatibilityResponse"
                      }
                    },
                    "count": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Auth error"
          },
          "429": {
            "description": "Rate or monthly limit exceeded"
          }
        }
      }
    },
    "/compatibility/explain": {
      "post": {
        "summary": "Compatibility + AI-generated narrative (paid tiers only)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "person_a",
                  "person_b"
                ],
                "properties": {
                  "person_a": {
                    "$ref": "#/components/schemas/Person"
                  },
                  "person_b": {
                    "$ref": "#/components/schemas/Person"
                  },
                  "context": {
                    "type": "string",
                    "enum": [
                      "romantic",
                      "business",
                      "friendship",
                      "coparenting"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/CompatibilityResponse"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "narrative": {
                          "type": "object",
                          "properties": {
                            "summary": {
                              "type": "string"
                            },
                            "coaching": {
                              "type": "string"
                            }
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "402": {
            "description": "Tier required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/profile/analyze": {
      "post": {
        "summary": "Single-person psychometric analysis",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "person": {
                    "$ref": "#/components/schemas/Person"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "report_id": {
                      "type": "string"
                    },
                    "report_type": {
                      "type": "string",
                      "const": "profile"
                    },
                    "frameworks_supported": {
                      "type": "integer",
                      "const": 21
                    },
                    "mbti_type": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "disc_type": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "strengths": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "growth_areas": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "analyzed_at": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/frameworks": {
      "get": {
        "security": [],
        "summary": "List supported frameworks",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "frameworks": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "name": {
                            "type": "string"
                          },
                          "category": {
                            "type": "string"
                          },
                          "values": {
                            "type": "array",
                            "items": {
                              "type": "string"
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/usage": {
      "get": {
        "summary": "Current key usage stats",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "tier": {
                      "type": "string"
                    },
                    "monthly_used": {
                      "type": "integer"
                    },
                    "monthly_remaining": {
                      "type": "integer"
                    },
                    "total_calls": {
                      "type": "integer"
                    },
                    "calls_last_7_days": {
                      "type": "integer"
                    },
                    "monthly_limit": {
                      "type": "integer"
                    },
                    "rate_limit_per_hour": {
                      "type": "integer"
                    },
                    "rate_limit_remaining": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/health": {
      "get": {
        "security": [],
        "summary": "Health check",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "ok"
                    },
                    "version": {
                      "type": "string"
                    },
                    "engine_version": {
                      "type": "string"
                    },
                    "timestamp": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/report/{id}": {
      "get": {
        "summary": "Retrieve an account-owned stored report (cache retention applies)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Stored report envelope",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "report_id": {
                      "type": "string"
                    },
                    "report": {
                      "type": "object",
                      "additionalProperties": true
                    },
                    "endpoint": {
                      "type": "string"
                    },
                    "generated_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "status_code": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Report not found or outside account"
          }
        }
      }
    },
    "/profile": {
      "post": {
        "summary": "Alias of POST /profile/analyze",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Person"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Structured profile analysis"
          },
          "400": {
            "description": "Validation error"
          }
        }
      }
    },
    "/webhooks": {
      "get": {
        "summary": "List account webhook subscriptions",
        "responses": {
          "200": {
            "description": "Webhook subscriptions"
          }
        }
      }
    },
    "/webhooks/subscribe": {
      "post": {
        "summary": "Subscribe to webhook events",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "url"
                ],
                "properties": {
                  "url": {
                    "type": "string",
                    "format": "uri",
                    "pattern": "^https://"
                  },
                  "events": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Subscription created; save returned secret"
          },
          "400": {
            "description": "Invalid destination"
          }
        }
      }
    },
    "/webhooks/unsubscribe": {
      "delete": {
        "summary": "Deactivate an account-owned webhook",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "id"
                ],
                "properties": {
                  "id": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Unsubscribed"
          },
          "400": {
            "description": "Missing id"
          }
        }
      }
    },
    "/openapi.json": {
      "get": {
        "summary": "This spec (no auth required)",
        "security": [],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    }
  }
}
