{
  "openapi": "3.0.3",
  "info": {
    "title": "GI — API de parceiros",
    "version": "1.2.0",
    "description": "Inclui scores editoriais de relevância, acessibilidade no texto-fonte, evidência de manchete e parcelas do ranking da home. Guia: /api/docs.php."
  },
  "servers": [
    {
      "url": "https://gazetadointerior.com.br/api/v1"
    }
  ],
  "security": [
    {
      "parceiro": []
    }
  ],
  "components": {
    "securitySchemes": {
      "parceiro": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "gi_live_…"
      }
    },
    "schemas": {
      "Noticia": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "status": {
            "type": "string",
            "enum": [
              "publicada"
            ]
          },
          "titulo": {
            "type": "string"
          },
          "subtitulo": {
            "type": "string",
            "nullable": true
          },
          "resumo": {
            "type": "string",
            "nullable": true
          },
          "texto": {
            "type": "string"
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "categoria": {
            "type": "object"
          },
          "publicada_em": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "atualizada_em": {
            "type": "string",
            "format": "date-time",
            "nullable": true,
            "description": "Data da última alteração editorial; recálculos de pontuação usam seus próprios campos de cálculo."
          },
          "tags_editoriais": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "nullable": true
          },
          "imagem": {
            "type": "string",
            "format": "uri",
            "nullable": true
          },
          "imagem_credito": {
            "type": "string",
            "nullable": true
          },
          "imagem_origem": {
            "type": "string",
            "nullable": true
          },
          "perfis": {
            "type": "object",
            "nullable": true
          },
          "pontuacoes": {
            "type": "object",
            "description": "Notas editoriais persistidas por notícia. Campos podem ser null antes do cálculo.",
            "properties": {
              "relevancia": {
                "type": "integer",
                "minimum": 0,
                "maximum": 10,
                "nullable": true
              },
              "acessibilidade": {
                "type": "object",
                "properties": {
                  "nota": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 10,
                    "nullable": true
                  },
                  "componentes": {
                    "type": "object",
                    "description": "Cinco componentes de 0 a 2: sintaxe, vocabulário, contexto, organização e números.",
                    "nullable": true
                  },
                  "metricas": {
                    "type": "object",
                    "properties": {
                      "palavras": {
                        "type": "integer"
                      },
                      "frases": {
                        "type": "integer"
                      },
                      "media_palavras_frase": {
                        "type": "number"
                      },
                      "frases_com_mais_30_palavras_pct": {
                        "type": "number"
                      },
                      "paragrafos": {
                        "type": "integer"
                      },
                      "media_palavras_paragrafo": {
                        "type": "number"
                      },
                      "paragrafos_com_mais_120_palavras_pct": {
                        "type": "number"
                      }
                    },
                    "nullable": true
                  },
                  "evidencias": {
                    "type": "object",
                    "nullable": true,
                    "description": "Evidências curtas associadas a cada componente."
                  }
                }
              },
              "manchete": {
                "type": "object",
                "properties": {
                  "tem_manchete": {
                    "type": "boolean"
                  },
                  "nota": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 10
                  },
                  "portais": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "nullable": true
                  },
                  "tipos": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "enum": [
                        "principal",
                        "secundaria",
                        "carrossel"
                      ]
                    },
                    "nullable": true
                  },
                  "ultima_observacao": {
                    "type": "string",
                    "format": "date-time",
                    "nullable": true
                  }
                }
              },
              "home": {
                "type": "object",
                "properties": {
                  "score": {
                    "type": "number",
                    "nullable": true
                  },
                  "parcelas": {
                    "type": "object",
                    "properties": {
                      "recencia": {
                        "type": "number"
                      },
                      "visitas": {
                        "type": "number"
                      },
                      "manchete": {
                        "type": "number"
                      },
                      "peso_recencia": {
                        "type": "number"
                      },
                      "peso_visitas": {
                        "type": "number"
                      },
                      "peso_manchete": {
                        "type": "number"
                      },
                      "visitas_reais": {
                        "type": "integer"
                      }
                    },
                    "nullable": true
                  },
                  "calculado_em": {
                    "type": "string",
                    "format": "date-time",
                    "nullable": true
                  }
                }
              }
            }
          }
        }
      },
      "EventoAlteracao": {
        "type": "object",
        "properties": {
          "evento_id": {
            "type": "integer"
          },
          "noticia_id": {
            "type": "integer"
          },
          "status": {
            "type": "string",
            "enum": [
              "publicada",
              "corrigida",
              "retirada"
            ]
          },
          "atualizado_em": {
            "type": "string",
            "format": "date-time"
          },
          "noticia": {
            "allOf": [
              {
                "$ref": "#/components/schemas/Noticia"
              }
            ],
            "nullable": true
          }
        }
      }
    }
  },
  "paths": {
    "/manchetes_sombra": {
      "get": {
        "summary": "Pontuação em sombra das manchetes externas",
        "description": "Última coleta válida em até 24 horas. Reavalia em modo sombra notícias recentes contra cartões externos observados em janela de até 12 horas. Vínculos não alteram nota, cota ou home.",
        "responses": {
          "200": {
            "description": "Coleta sombra",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "modo",
                    "coletado_em",
                    "portais",
                    "dados"
                  ],
                  "properties": {
                    "modo": {
                      "type": "string",
                      "enum": [
                        "sombra"
                      ]
                    },
                    "coletado_em": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true
                    },
                    "vinculos_modo": {
                      "type": "string",
                      "enum": ["sombra"],
                      "description": "Resultado experimental, não usado para publicação ou ranking."
                    },
                    "vinculos_janela_horas": {
                      "type": "integer",
                      "description": "Janela máxima entre notícia e observação do destaque externo."
                    },
                    "vinculos_recalculado_em": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "portais": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "portal": {
                            "type": "string"
                          },
                          "estado": {
                            "type": "string",
                            "enum": [
                              "completa",
                              "parcial",
                              "erro"
                            ]
                          },
                          "cartoes": {
                            "type": "integer",
                            "minimum": 0
                          }
                        }
                      }
                    },
                    "dados": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "Identificador do fato na coleta"
                          },
                          "titulo": {
                            "type": "string"
                          },
                          "presenca_portais": {
                            "type": "array",
                            "description": "Presença observada por portal em coletas arquivadas nas últimas 24 horas. O intervalo é um limite inferior entre capturas, não prova de presença contínua.",
                            "items": {
                              "type": "object",
                              "properties": {
                                "portal": {"type": "string"},
                                "primeira_observacao": {"type": "string", "format": "date-time"},
                                "ultima_observacao": {"type": "string", "format": "date-time"},
                                "tempo_no_ar_segundos": {"type": "integer", "minimum": 0},
                                "rodadas_observadas": {"type": "integer", "minimum": 1},
                                "coletas_analisadas": {"type": "integer", "minimum": 1},
                                "rodadas_sem_cartao": {"type": "integer", "minimum": 0, "description": "Coletas completas entre a primeira e a última presença em que o cartão não apareceu."},
                                "sem_lacunas_entre_coletas": {"type": "boolean"},
                                "tipo_ultima_observacao": {"type": "string", "enum": ["principal", "secundaria", "carrossel", "abertura"]}
                              }
                            }
                          },
                          "vinculos_sombra": {
                            "type": "array",
                            "description": "Notícias candidatas vinculadas automaticamente em sombra. Mesmo fato pode herdar nota somente após validação independente; cobertura relacionada não herda nota.",
                            "items": {
                              "type": "object",
                              "required": ["noticia_id", "titulo", "publicada_em", "tipo", "evidencia"],
                              "properties": {
                                "noticia_id": {"type": "integer"},
                                "titulo": {"type": "string"},
                                "publicada_em": {"type": "string", "format": "date-time"},
                                "tipo": {"type": "string", "enum": ["mesmo_fato", "cobertura_relacionada"]},
                                "evidencia": {"type": "string"}
                              }
                            }
                          },
                          "exposicao": {
                            "type": "number",
                            "description": "Maior 10 × peso da posição × fator de tempo observado no fato."
                          },
                          "abrangencia": {
                            "type": "number",
                            "description": "Soma da exposição × 0,15 × fator de tempo de cada portal adicional."
                          },
                          "nota_bruta": {
                            "type": "number",
                            "description": "Exposição + abrangência, antes do teto."
                          },
                          "nota": {
                            "type": "number",
                            "minimum": 0,
                            "maximum": 20,
                            "description": "min(20, nota_bruta)."
                          },
                          "home": {
                            "type": "number",
                            "minimum": 0,
                            "maximum": 18,
                            "description": "Contribuição simulada da manchete à home: 18 × nota/20."
                          },
                          "base": {
                            "type": "string",
                            "nullable": true
                          },
                          "portais": {
                            "type": "object",
                            "additionalProperties": {
                              "type": "object",
                              "properties": {
                                "valor": {
                                  "type": "number"
                                },
                                "tempo": {
                                  "type": "number",
                                  "description": "Fator de decaimento temporal da observação, entre 0 e 1."
                                },
                                "tipo": {
                                  "type": "string",
                                  "enum": [
                                    "principal",
                                    "secundaria",
                                    "carrossel",
                                    "abertura"
                                  ]
                                },
                                "bonus": {
                                  "type": "number",
                                  "description": "Contribuição deste portal à abrangência; zero para o portal base."
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Autenticação necessária"
          }
        }
      }
    },
    "/noticias": {
      "get": {
        "summary": "Listar notícias",
        "parameters": [
          {
            "name": "pagina",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 1000,
              "default": 1
            }
          },
          {
            "name": "limite",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50,
              "default": 20
            }
          },
          {
            "name": "categoria_id",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          },
          {
            "name": "atualizada_apos",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "Filtro estrito por data de atualização; somente matérias atualmente publicadas. Use /noticias/alteracoes para consultar retiradas."
          }
        ],
        "responses": {
          "200": {
            "description": "Lista paginada de matérias publicadas",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "dados": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Noticia"
                      }
                    },
                    "paginacao": {
                      "type": "object"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Erro",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "erro": {
                      "type": "object",
                      "properties": {
                        "codigo": {
                          "type": "string"
                        },
                        "mensagem": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Erro",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "erro": {
                      "type": "object",
                      "properties": {
                        "codigo": {
                          "type": "string"
                        },
                        "mensagem": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Erro",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "erro": {
                      "type": "object",
                      "properties": {
                        "codigo": {
                          "type": "string"
                        },
                        "mensagem": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "405": {
            "description": "Erro",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "erro": {
                      "type": "object",
                      "properties": {
                        "codigo": {
                          "type": "string"
                        },
                        "mensagem": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Erro",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "erro": {
                      "type": "object",
                      "properties": {
                        "codigo": {
                          "type": "string"
                        },
                        "mensagem": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Erro",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "erro": {
                      "type": "object",
                      "properties": {
                        "codigo": {
                          "type": "string"
                        },
                        "mensagem": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/noticias/{id}": {
      "get": {
        "summary": "Consultar uma notícia",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Matéria publicada",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "dados": {
                      "$ref": "#/components/schemas/Noticia"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Erro",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "erro": {
                      "type": "object",
                      "properties": {
                        "codigo": {
                          "type": "string"
                        },
                        "mensagem": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Erro",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "erro": {
                      "type": "object",
                      "properties": {
                        "codigo": {
                          "type": "string"
                        },
                        "mensagem": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Erro",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "erro": {
                      "type": "object",
                      "properties": {
                        "codigo": {
                          "type": "string"
                        },
                        "mensagem": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "405": {
            "description": "Erro",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "erro": {
                      "type": "object",
                      "properties": {
                        "codigo": {
                          "type": "string"
                        },
                        "mensagem": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Erro",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "erro": {
                      "type": "object",
                      "properties": {
                        "codigo": {
                          "type": "string"
                        },
                        "mensagem": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Erro",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "erro": {
                      "type": "object",
                      "properties": {
                        "codigo": {
                          "type": "string"
                        },
                        "mensagem": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/categorias": {
      "get": {
        "summary": "Listar categorias ativas",
        "responses": {
          "200": {
            "description": "Consulta concluída",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "dados": {}
                  }
                }
              }
            }
          },
          "400": {
            "description": "Erro",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "erro": {
                      "type": "object",
                      "properties": {
                        "codigo": {
                          "type": "string"
                        },
                        "mensagem": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Erro",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "erro": {
                      "type": "object",
                      "properties": {
                        "codigo": {
                          "type": "string"
                        },
                        "mensagem": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Erro",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "erro": {
                      "type": "object",
                      "properties": {
                        "codigo": {
                          "type": "string"
                        },
                        "mensagem": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "405": {
            "description": "Erro",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "erro": {
                      "type": "object",
                      "properties": {
                        "codigo": {
                          "type": "string"
                        },
                        "mensagem": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Erro",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "erro": {
                      "type": "object",
                      "properties": {
                        "codigo": {
                          "type": "string"
                        },
                        "mensagem": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Erro",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "erro": {
                      "type": "object",
                      "properties": {
                        "codigo": {
                          "type": "string"
                        },
                        "mensagem": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/perfis": {
      "get": {
        "summary": "Listar perfis e escalas editoriais",
        "responses": {
          "200": {
            "description": "Consulta concluída",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "dados": {}
                  }
                }
              }
            }
          },
          "400": {
            "description": "Erro",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "erro": {
                      "type": "object",
                      "properties": {
                        "codigo": {
                          "type": "string"
                        },
                        "mensagem": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Erro",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "erro": {
                      "type": "object",
                      "properties": {
                        "codigo": {
                          "type": "string"
                        },
                        "mensagem": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Erro",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "erro": {
                      "type": "object",
                      "properties": {
                        "codigo": {
                          "type": "string"
                        },
                        "mensagem": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "405": {
            "description": "Erro",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "erro": {
                      "type": "object",
                      "properties": {
                        "codigo": {
                          "type": "string"
                        },
                        "mensagem": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Erro",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "erro": {
                      "type": "object",
                      "properties": {
                        "codigo": {
                          "type": "string"
                        },
                        "mensagem": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Erro",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "erro": {
                      "type": "object",
                      "properties": {
                        "codigo": {
                          "type": "string"
                        },
                        "mensagem": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/noticias/alteracoes": {
      "get": {
        "summary": "Listar alterações com cursor retomável",
        "description": "Depois de gravar todos os eventos, persista proximo_cursor. Retome usando cursor salvo. Os eventos são append-only e podem repetir noticia_id; aplique-os de forma idempotente.",
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0
            }
          },
          {
            "name": "limite",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Eventos ordenados por sequência persistente",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "dados": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/EventoAlteracao"
                      }
                    },
                    "paginacao": {
                      "type": "object",
                      "properties": {
                        "cursor": {
                          "type": "integer"
                        },
                        "proximo_cursor": {
                          "type": "integer"
                        },
                        "limite": {
                          "type": "integer"
                        },
                        "tem_mais": {
                          "type": "boolean"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Cursor ou limite inválido"
          },
          "401": {
            "description": "Chave ausente ou inválida"
          },
          "429": {
            "description": "Limite excedido"
          }
        }
      }
    }
  }
}
