{
  "openapi": "3.1.0",
  "info": {
    "title": "CheckAPI",
    "version": "1.0.0",
    "description": "Автоматична перевірка українських банківських квитанцій за фото: звірка суми і картки отримувача за ~1 секунду.",
    "contact": {"name": "CheckAPI Support", "url": "https://t.me/sarmkadan"}
  },
  "servers": [{"url": "https://check.sarmkadan.com"}],
  "paths": {
    "/api/v1/verify": {
      "post": {
        "operationId": "verifyReceipt",
        "summary": "Перевірити квитанцію",
        "description": "Надішліть фото квитанції, очікувану суму та останні 4 цифри картки отримувача — отримайте вердикт.",
        "security": [{"apiKey": []}],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": ["image", "expectedAmount", "expectedCardLast4"],
                "properties": {
                  "image": {"type": "string", "format": "binary", "description": "Фото квитанції (jpg/png/webp, до 10 МБ)"},
                  "expectedAmount": {"type": "number", "description": "Очікувана сума в гривнях"},
                  "expectedCardLast4": {"type": "string", "pattern": "^\\d{4}$", "description": "Останні 4 цифри картки отримувача"}
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Результат перевірки",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "verified": {"type": "boolean"},
                    "confidence": {"type": "number"},
                    "detectedAmount": {"type": "number", "nullable": true},
                    "detectedCardLast4": {"type": "string", "nullable": true},
                    "reason": {"type": "string", "enum": ["confirmed", "not_confirmed", "rejection_or_payment_screen_detected", "amount_not_found_or_mismatch", "card_not_found_or_mismatch", "amount_and_card_not_found", "processing_error"]},
                    "durationMs": {"type": "integer"},
                    "checksLeft": {"type": "integer"}
                  }
                }
              }
            }
          },
          "401": {"description": "Невірний або відсутній API-ключ"},
          "402": {"description": "Пакет перевірок вичерпано"},
          "413": {"description": "Зображення перевищує 10 МБ"},
          "415": {"description": "Непідтримуваний формат (тільки jpg/png/webp)"},
          "422": {"description": "Невірні вхідні дані"},
          "502": {"description": "Тимчасова недоступність бекенда"}
        }
      }
    },
    "/api/health": {
      "get": {
        "operationId": "healthCheck",
        "summary": "Перевірка доступності",
        "responses": {"200": {"description": "Сервіс працює", "content": {"application/json": {"schema": {"type": "object", "properties": {"status": {"type": "string"}}}}}}}
      }
    },
    "/api/uptime": {
      "get": {
        "operationId": "uptimeStats",
        "summary": "Статистика доступності за 30 днів",
        "responses": {"200": {"description": "Uptime stats", "content": {"application/json": {"schema": {"type": "object", "properties": {"uptime30d": {"type": "number"}, "uptime24h": {"type": "number"}, "medianResponseMs": {"type": "integer"}, "checks": {"type": "integer"}}}}}}}
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKey": {"type": "apiKey", "in": "header", "name": "X-API-Key"}
    }
  }
}
