{
  "openapi": "3.0.3",
  "info": {
    "title": "SeenByHuman API",
    "version": "0.1.0",
    "description": "Zleć żywego testera apki zrobionej z AI. Zlecenie może złożyć człowiek (landing) lub agent AI (ten API, bearer token)."
  },
  "servers": [{ "url": "http://localhost:8787" }],
  "paths": {
    "/api/orders": {
      "post": {
        "summary": "Złóż zlecenie testu (człowiek lub agent)",
        "security": [{}, { "bearer": [] }],
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "$ref": "#/components/schemas/OrderInput" } } }
        },
        "responses": { "201": { "description": "Utworzone zlecenie", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Order" } } } } }
      }
    },
    "/api/orders/{id}": {
      "get": {
        "summary": "Stan zlecenia + raport (agent odpytuje to po werdykt)",
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "OK", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Order" } } } }, "404": { "description": "Nie ma" } }
      }
    },
    "/api/orders/{id}/checkout": {
      "post": { "summary": "Utwórz sesję Stripe Checkout (fake-door, bez go-live bez zgody)", "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }], "responses": { "200": { "description": "URL do zapłaty" } } }
    },
    "/api/orders/{id}/report": {
      "post": { "summary": "Tester/operator wgrywa raport (werdykt + komentarz + dowody)", "security": [{ "bearer": [] }], "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }], "responses": { "201": { "description": "OK" } } }
    },
    "/api/orders/{id}/status": {
      "post": { "summary": "Zmień status zlecenia (operator)", "security": [{ "bearer": [] }], "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }], "responses": { "200": { "description": "OK" } } }
    },
    "/api/testers": { "post": { "summary": "Zapis testera (podaż)", "responses": { "201": { "description": "OK" } } } },
    "/api/leads": { "post": { "summary": "Zapis na waitlistę popytu", "responses": { "201": { "description": "OK" } } } },
    "/api/stats": { "get": { "summary": "Liczniki (zlecenia, opłacone, testerzy, leady)", "responses": { "200": { "description": "OK" } } } },
    "/healthz": { "get": { "summary": "Health check", "responses": { "200": { "description": "OK" } } } }
  },
  "components": {
    "securitySchemes": { "bearer": { "type": "http", "scheme": "bearer", "description": "HT_API_KEY" } },
    "schemas": {
      "OrderInput": {
        "type": "object",
        "required": ["app_url", "brief"],
        "properties": {
          "app_url": { "type": "string", "example": "https://my-app.lovable.app" },
          "brief": { "type": "string", "example": "Signup → nagraj notkę głosową → zapisz. Czy niemiecki tekst brzmi naturalnie?" },
          "service": { "type": "string", "enum": ["localization_sweep", "first_impression", "full_walkthrough"], "default": "localization_sweep" },
          "market": { "type": "string", "example": "de" },
          "access_login": { "type": "string" },
          "access_secret": { "type": "string" },
          "price_cents": { "type": "integer", "default": 800 },
          "currency": { "type": "string", "default": "usd" },
          "contact_email": { "type": "string" }
        }
      },
      "Order": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "status": { "type": "string", "enum": ["new", "paid", "assigned", "in_progress", "reported", "delivered", "canceled"] },
          "paid": { "type": "boolean" },
          "reports": { "type": "array", "items": { "$ref": "#/components/schemas/Report" } }
        }
      },
      "Report": {
        "type": "object",
        "properties": {
          "verdict": { "type": "string", "enum": ["pass", "fail", "needs_work"] },
          "comment": { "type": "string" },
          "evidence": { "type": "object", "description": "Linki do nagrania ekranu i zrzutów" }
        }
      }
    }
  }
}
