{
  "openapi": "3.1.0",
  "info": {
    "title": "UAI Link & Catálogo Core API",
    "version": "2.1.0",
    "description": "Especificação OpenAPI 3.1.0 oficial do UAI Link. Oferece endpoints para consulta de BioLinks públicos, catálogos interativos de produtos, telemetria de cliques, webhooks de pedidos e checkout automatizado via Pix no Mercado Pago.",
    "contact": {
      "name": "Suporte Técnico UAI Link",
      "email": "suporte@uailink.online",
      "url": "https://uailink.online"
    }
  },
  "servers": [
    {
      "url": "https://api.uailink.online",
      "description": "Servidor de Produção API"
    },
    {
      "url": "https://uailink.online",
      "description": "Servidor de Produção Web & Edge"
    }
  ],
  "paths": {
    "/health": {
      "get": {
        "summary": "Health check do ecossistema",
        "operationId": "checkHealth",
        "responses": {
          "200": {
            "description": "Serviço operacional",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "service": {
                      "type": "string",
                      "example": "uai-link-api"
                    },
                    "status": {
                      "type": "string",
                      "example": "online"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/public/pricing": {
      "get": {
        "summary": "Consulta tabela pública de planos e preços",
        "operationId": "getPricingPlans",
        "responses": {
          "200": {
            "description": "Planos e valores vigentes em BRL",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PricingPlans"
                }
              }
            }
          }
        }
      }
    },
    "/api/public/{slug}": {
      "get": {
        "summary": "Consulta dados públicos de perfil e BioLink",
        "operationId": "getPublicBioLink",
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Slug da página pública do cliente"
          }
        ],
        "responses": {
          "200": {
            "description": "Perfil carregado com sucesso",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PublicProfile"
                }
              }
            }
          },
          "404": {
            "description": "Página indisponível ou inexistente"
          }
        }
      }
    },
    "/api/public/{slug}/click": {
      "post": {
        "summary": "Registra telemetria de clique em botão",
        "operationId": "trackButtonClick",
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "title": {
                    "type": "string",
                    "example": "Agendar Consulta"
                  },
                  "type": {
                    "type": "string",
                    "example": "whatsapp"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "204": {
            "description": "Clique registrado com sucesso"
          }
        }
      }
    },
    "/api/public/{slug}/catalogo": {
      "get": {
        "summary": "Consulta catálogo completo de produtos e variações",
        "operationId": "getPublicCatalog",
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Catálogo retornado com produtos e variantes",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CatalogResponse"
                }
              }
            }
          },
          "404": {
            "description": "Catálogo desativado ou não encontrado"
          }
        }
      }
    },
    "/api/public/{slug}/catalogo/order-notification": {
      "post": {
        "summary": "Notificação de pedido gerado no carrinho",
        "operationId": "notifyOrderCreated",
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/OrderNotificationPayload"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Notificação processada com sucesso"
          }
        }
      }
    },
    "/api/payments/mercadopago/webhook": {
      "post": {
        "summary": "Webhook de recebimento e ativação de Pix Mercado Pago",
        "operationId": "handleMercadoPagoWebhook",
        "parameters": [
          {
            "name": "x-signature",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-request-id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Evento de pagamento processado"
          },
          "401": {
            "description": "Assinatura inválida"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "PricingPlans": {
        "type": "object",
        "properties": {
          "link": {
            "type": "object",
            "properties": {
              "monthly": {
                "type": "number",
                "example": 9.9
              },
              "annual": {
                "type": "number",
                "example": 67.9
              }
            }
          },
          "catalog": {
            "type": "object",
            "properties": {
              "monthly": {
                "type": "number",
                "example": 19.9
              },
              "annual": {
                "type": "number",
                "example": 139.9
              }
            }
          },
          "combo": {
            "type": "object",
            "properties": {
              "monthly": {
                "type": "number",
                "example": 24.9
              },
              "annual": {
                "type": "number",
                "example": 174.9
              }
            }
          }
        }
      },
      "PublicProfile": {
        "type": "object",
        "properties": {
          "page": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "slug": {
                "type": "string"
              },
              "headline": {
                "type": "string"
              },
              "description": {
                "type": "string"
              },
              "logo_url": {
                "type": "string",
                "nullable": true
              },
              "cover_url": {
                "type": "string",
                "nullable": true
              },
              "theme": {
                "type": "string"
              },
              "palette": {
                "type": "string"
              },
              "buttons": {
                "type": "array",
                "items": {
                  "type": "object"
                }
              }
            }
          }
        }
      },
      "CatalogResponse": {
        "type": "object",
        "properties": {
          "catalog": {
            "type": "object"
          },
          "categories": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "products": {
            "type": "array",
            "items": {
              "type": "object"
            }
          }
        }
      },
      "OrderNotificationPayload": {
        "type": "object",
        "properties": {
          "order_id": {
            "type": "string"
          },
          "customer_phone": {
            "type": "string"
          },
          "customer_name": {
            "type": "string"
          },
          "total_amount": {
            "type": "number"
          },
          "items": {
            "type": "array",
            "items": {
              "type": "object"
            }
          }
        }
      }
    }
  }
}