{
  "openapi": "3.1.0",
  "info": {
    "title": "AuditaAI Public REST API",
    "version": "1.0.0",
    "description": "API oficial do AuditaAI para triagem inteligente de editais de licitação da Nova Lei nº 14.133/2021, Score de Bom Pagador do órgão licitante (Tesouro Nacional / SICONFI), geração de minutas de impugnação e cobrança PIX instantânea.",
    "contact": {
      "name": "Suporte Técnico AuditaAI",
      "url": "https://auditaai.online",
      "email": "contato@auditaai.online"
    },
    "license": {
      "name": "Proprietary",
      "url": "https://auditaai.online/terms"
    }
  },
  "servers": [
    {
      "url": "https://auditaai.online",
      "description": "Servidor de Produção Oficial"
    }
  ],
  "paths": {
    "/api/analyze": {
      "post": {
        "summary": "Auditar edital em PDF via Gemini 2.0 Flash",
        "description": "Recebe o arquivo binário PDF do edital e retorna checklist de habilitação (jurídica, fiscal, técnica, econômico-financeira), prazos de impugnação, riscos eliminatórios e o Score de Bom Pagador.",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "file"
                ],
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary",
                    "description": "Arquivo PDF do edital"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Auditoria concluída com sucesso",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "analysis_id": {
                      "type": "string",
                      "example": "4a7c2b81-9f10-410a"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "orgao_nome": {
                          "type": "string",
                          "example": "Prefeitura de Campinas"
                        },
                        "numero_edital": {
                          "type": "string",
                          "example": "Pregão 14/2026"
                        },
                        "valor_estimado": {
                          "type": "string",
                          "example": "R$ 850.000,00"
                        },
                        "veredito_geral": {
                          "type": "string",
                          "example": "GO"
                        },
                        "score_bom_pagador": {
                          "type": "object",
                          "properties": {
                            "score": {
                              "type": "integer",
                              "example": 92
                            },
                            "label": {
                              "type": "string",
                              "example": "Excelente Pagador"
                            },
                            "capag_tesouro": {
                              "type": "string",
                              "example": "CAPAG A"
                            },
                            "prazo_medio_estimado": {
                              "type": "string",
                              "example": "20 a 35 dias"
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/score/lookup": {
      "post": {
        "summary": "Consultar Score de Bom Pagador e solvência fiscal",
        "description": "Verifica a reputação financeira de qualquer órgão público brasileiro cruzando dados do Tesouro Nacional (CAPAG), SICONFI e histórico de pagamentos.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "orgao_nome"
                ],
                "properties": {
                  "orgao_nome": {
                    "type": "string",
                    "example": "Prefeitura Municipal de Curitiba"
                  },
                  "uf": {
                    "type": "string",
                    "example": "PR"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Score fiscal retornado",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "score": {
                          "type": "integer",
                          "example": 88
                        },
                        "badge": {
                          "type": "string",
                          "example": "EXCELENTE_PAGADOR"
                        },
                        "capag_tesouro": {
                          "type": "string",
                          "example": "CAPAG A"
                        },
                        "prazo_medio_estimado": {
                          "type": "string",
                          "example": "22 a 35 dias"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/checkout/pix": {
      "post": {
        "summary": "Gerar cobrança instantânea PIX via Mercado Pago",
        "description": "Gera QR Code e código Copia e Cola para desbloqueio do dossiê completo de auditoria do edital.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "analysis_id"
                ],
                "properties": {
                  "analysis_id": {
                    "type": "string",
                    "example": "4a7c2b81-9f10-410a"
                  },
                  "amount": {
                    "type": "number",
                    "example": 27.9
                  },
                  "payer_email": {
                    "type": "string",
                    "example": "licitante@empresa.com"
                  },
                  "whatsapp_phone": {
                    "type": "string",
                    "example": "5511999998888"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "PIX gerado com sucesso",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "payment_id": {
                      "type": "string",
                      "example": "182412755188"
                    },
                    "status": {
                      "type": "string",
                      "example": "pending"
                    },
                    "qr_code_text": {
                      "type": "string",
                      "example": "00020126580014br.gov.bcb.pix..."
                    },
                    "qr_code_base64": {
                      "type": "string",
                      "example": "iVBORw0KGgoAAA..."
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/dispatch/whatsapp": {
      "post": {
        "summary": "Disparar dossiê executivo para WhatsApp via Evolution API",
        "description": "Envia o resumo executivo, prazos fatais de impugnação e link do checklist completo diretamente para o número informado.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "phone",
                  "analysis_id"
                ],
                "properties": {
                  "phone": {
                    "type": "string",
                    "example": "5511999998888"
                  },
                  "analysis_id": {
                    "type": "string",
                    "example": "4a7c2b81-9f10-410a"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Mensagem enviada com sucesso",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "phone": {
                      "type": "string",
                      "example": "5511999998888"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/health": {
      "get": {
        "summary": "Status do Motor e Conexões",
        "responses": {
          "200": {
            "description": "Motor operacional",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "online"
                    },
                    "engine": {
                      "type": "string",
                      "example": "LicitAI / AuditaAI v1.0"
                    },
                    "gemini_model": {
                      "type": "string",
                      "example": "gemini-2.0-flash"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}