{
  "openapi": "3.1.0",
  "info": {
    "title": "Super Lambda API",
    "version": "1.0.0",
    "description": "JSON API for the Super Lambda hosting site: account signup/login (cookie sessions), the current-user endpoint, contact submissions, and a health check.",
    "contact": { "name": "Super Lambda", "url": "https://superlambda.com/contact" },
    "license": { "name": "Proprietary" }
  },
  "servers": [{ "url": "https://superlambda.com", "description": "Production" }],
  "tags": [
    { "name": "auth", "description": "Account registration and session authentication" },
    { "name": "account", "description": "Authenticated account endpoints" },
    { "name": "public", "description": "Unauthenticated endpoints" }
  ],
  "paths": {
    "/api/health": {
      "get": {
        "tags": ["public"],
        "summary": "Service health check",
        "operationId": "getHealth",
        "responses": {
          "200": {
            "description": "Service is healthy",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": { "type": "boolean" },
                    "status": { "type": "string", "examples": ["ok"] },
                    "service": { "type": "string" },
                    "time": { "type": "string", "format": "date-time" }
                  },
                  "required": ["ok", "status"]
                }
              }
            }
          }
        }
      }
    },
    "/api/signup": {
      "post": {
        "tags": ["auth"],
        "summary": "Create an account and start a session",
        "operationId": "signup",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/SignupRequest" }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Account created. A session cookie (sl_session) is set.",
            "headers": { "Set-Cookie": { "schema": { "type": "string" }, "description": "sl_session=<token>; HttpOnly; Secure; SameSite=Lax" } },
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/UserResponse" } } }
          },
          "400": { "$ref": "#/components/responses/Error" },
          "409": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/api/login": {
      "post": {
        "tags": ["auth"],
        "summary": "Authenticate and start a session",
        "operationId": "login",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/LoginRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Authenticated. A session cookie (sl_session) is set.",
            "headers": { "Set-Cookie": { "schema": { "type": "string" } } },
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/UserResponse" } } }
          },
          "400": { "$ref": "#/components/responses/Error" },
          "401": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/api/logout": {
      "post": {
        "tags": ["account"],
        "summary": "Destroy the current session",
        "operationId": "logout",
        "security": [{ "sessionCookie": [] }],
        "responses": {
          "200": {
            "description": "Session destroyed; the session cookie is cleared.",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Ok" } } }
          }
        }
      }
    },
    "/api/me": {
      "get": {
        "tags": ["account"],
        "summary": "Get the currently authenticated user",
        "operationId": "getMe",
        "security": [{ "sessionCookie": [] }],
        "responses": {
          "200": { "description": "The current user", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/UserResponse" } } } },
          "401": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/api/contact": {
      "post": {
        "tags": ["public"],
        "summary": "Submit a contact message",
        "operationId": "contact",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/ContactRequest" }
            }
          }
        },
        "responses": {
          "200": { "description": "Message received", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Ok" } } } },
          "400": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "sessionCookie": {
        "type": "apiKey",
        "in": "cookie",
        "name": "sl_session",
        "description": "Opaque session token issued by /api/signup or /api/login and delivered as an HttpOnly cookie."
      }
    },
    "schemas": {
      "SignupRequest": {
        "type": "object",
        "required": ["name", "email", "password"],
        "properties": {
          "name": { "type": "string", "minLength": 2, "maxLength": 120 },
          "email": { "type": "string", "format": "email", "maxLength": 200 },
          "password": { "type": "string", "minLength": 8, "maxLength": 200 }
        }
      },
      "LoginRequest": {
        "type": "object",
        "required": ["email", "password"],
        "properties": {
          "email": { "type": "string", "format": "email" },
          "password": { "type": "string" }
        }
      },
      "ContactRequest": {
        "type": "object",
        "required": ["name", "email", "message"],
        "properties": {
          "name": { "type": "string", "maxLength": 120 },
          "email": { "type": "string", "format": "email", "maxLength": 200 },
          "message": { "type": "string", "minLength": 10, "maxLength": 5000 }
        }
      },
      "User": {
        "type": "object",
        "properties": {
          "id": { "type": "integer" },
          "name": { "type": "string" },
          "email": { "type": "string", "format": "email" }
        }
      },
      "UserResponse": {
        "type": "object",
        "properties": {
          "ok": { "type": "boolean" },
          "user": { "$ref": "#/components/schemas/User" }
        },
        "required": ["ok", "user"]
      },
      "Ok": {
        "type": "object",
        "properties": { "ok": { "type": "boolean" } },
        "required": ["ok"]
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "ok": { "type": "boolean", "const": false },
          "error": { "type": "string" }
        },
        "required": ["ok", "error"]
      }
    },
    "responses": {
      "Error": {
        "description": "Request error",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } }
      },
      "RateLimited": {
        "description": "Too many requests",
        "headers": { "Retry-After": { "schema": { "type": "integer" }, "description": "Seconds until the limit resets" } },
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } }
      }
    }
  }
}
