{
  "openapi": "3.1.0",
  "info": {
    "title": "Family Doctor AI Public API",
    "version": "1.0.0",
    "description": "Discovery and subscription-oriented endpoints for Family Doctor AI."
  },
  "servers": [
    {
      "url": "https://familydoctor.robopioneer.com"
    }
  ],
  "paths": {
    "/api/health": {
      "get": {
        "summary": "Health check",
        "responses": {
          "200": {
            "description": "Service status"
          }
        }
      }
    },
    "/api/discovery": {
      "get": {
        "summary": "Machine-readable discovery metadata",
        "responses": {
          "200": {
            "description": "Discovery payload"
          }
        }
      }
    },
    "/api/stripe/create-checkout-session": {
      "post": {
        "summary": "Create a Stripe checkout session for a paid plan",
        "security": [
          {
            "firebaseBearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["plan", "billing"],
                "properties": {
                  "plan": {
                    "type": "string",
                    "enum": ["plus", "premium"]
                  },
                  "billing": {
                    "type": "string",
                    "enum": ["monthly", "yearly"]
                  },
                  "source": {
                    "type": "string"
                  },
                  "successPath": {
                    "type": "string"
                  },
                  "cancelPath": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Checkout session created"
          },
          "401": {
            "description": "Unauthorized"
          }
        }
      }
    },
    "/api/stripe/create-portal-session": {
      "post": {
        "summary": "Create Stripe customer portal session",
        "security": [
          {
            "firebaseBearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Portal URL created"
          }
        }
      }
    },
    "/api/stripe/subscription-status": {
      "get": {
        "summary": "Get current subscription status for authenticated user",
        "security": [
          {
            "firebaseBearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Subscription status payload"
          }
        }
      }
    },
    "/api/attribution": {
      "post": {
        "summary": "Store landing and CTA attribution events",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["sessionId", "source", "variant", "eventType"],
                "properties": {
                  "sessionId": { "type": "string" },
                  "source": { "type": "string" },
                  "variant": { "type": "string", "enum": ["a", "b"] },
                  "eventType": {
                    "type": "string",
                    "enum": ["landing_view", "cta_click", "pricing_view", "checkout_start", "register_view", "login_view"]
                  },
                  "pagePath": { "type": "string" },
                  "plan": { "type": "string" },
                  "billing": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Attribution event accepted"
          }
        }
      },
      "get": {
        "summary": "Read attribution aggregates",
        "parameters": [
          { "name": "days", "in": "query", "schema": { "type": "integer", "minimum": 1, "maximum": 90 } },
          { "name": "source", "in": "query", "schema": { "type": "string" } }
        ],
        "responses": {
          "200": { "description": "Attribution summary" },
          "403": { "description": "Forbidden when analytics key is required" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "firebaseBearer": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "Firebase ID Token"
      }
    }
  }
}
