{
  "openapi": "3.1.0",
  "info": {
    "title": "Readyzap API",
    "version": "1.0.0",
    "description": "Consultas autenticadas de conta, chips e campanhas."
  },
  "servers": [
    {
      "url": "https://db.readyzap.com.br/functions/v1/api"
    }
  ],
  "security": [
    {
      "ReadyzapKey": []
    }
  ],
  "tags": [
    {
      "name": "Conta"
    },
    {
      "name": "Aquecedor"
    },
    {
      "name": "Disparador"
    }
  ],
  "paths": {
    "/v1/account": {
      "get": {
        "operationId": "get_account",
        "summary": "Consultar conta",
        "description": "Consulte informações da sua conta. Disponível em planos Pro e Business ativos.",
        "tags": [
          "Conta"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Consulta concluída. Exemplo fictício e resumido.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "anyOf": [
                        {
                          "$ref": "#/components/schemas/Conta"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    }
                  },
                  "required": [
                    "data"
                  ]
                },
                "example": {
                  "data": {
                    "plan": "pro",
                    "plan_status": "active",
                    "plan_expires_at": "2027-01-01T00:00:00Z",
                    "chip_limit": 3
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Erro401"
          },
          "403": {
            "$ref": "#/components/responses/Erro403"
          },
          "429": {
            "$ref": "#/components/responses/Erro429"
          },
          "503": {
            "$ref": "#/components/responses/Erro503"
          }
        }
      }
    },
    "/v1/chips": {
      "get": {
        "operationId": "list_chips",
        "summary": "Listar chips",
        "description": "Consulte informações da sua conta. Disponível em planos Pro e Business ativos.",
        "tags": [
          "Aquecedor"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Limit"
          },
          {
            "$ref": "#/components/parameters/Offset"
          }
        ],
        "responses": {
          "200": {
            "description": "Consulta concluída. Exemplo fictício e resumido.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Chip"
                      }
                    },
                    "limit": {
                      "type": "integer"
                    },
                    "offset": {
                      "type": "integer"
                    }
                  },
                  "required": [
                    "data",
                    "limit",
                    "offset"
                  ]
                },
                "example": {
                  "data": [
                    {
                      "id": "11111111-1111-1111-1111-111111111111",
                      "display_name": "Loja exemplo",
                      "customer_status": "aquecendo",
                      "warming_day": 5
                    }
                  ],
                  "limit": 50,
                  "offset": 0
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Erro401"
          },
          "403": {
            "$ref": "#/components/responses/Erro403"
          },
          "429": {
            "$ref": "#/components/responses/Erro429"
          },
          "503": {
            "$ref": "#/components/responses/Erro503"
          }
        }
      }
    },
    "/v1/chips/{id}": {
      "get": {
        "operationId": "get_chip",
        "summary": "Consultar chip",
        "description": "Consulte informações da sua conta. Disponível em planos Pro e Business ativos.",
        "tags": [
          "Aquecedor"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "Consulta concluída. Exemplo fictício e resumido.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Chip"
                    }
                  },
                  "required": [
                    "data"
                  ]
                },
                "example": {
                  "data": {
                    "id": "11111111-1111-1111-1111-111111111111",
                    "display_name": "Loja exemplo",
                    "customer_status": "aquecendo",
                    "warming_day": 5
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Erro400"
          },
          "401": {
            "$ref": "#/components/responses/Erro401"
          },
          "403": {
            "$ref": "#/components/responses/Erro403"
          },
          "404": {
            "$ref": "#/components/responses/Erro404"
          },
          "429": {
            "$ref": "#/components/responses/Erro429"
          },
          "503": {
            "$ref": "#/components/responses/Erro503"
          }
        }
      }
    },
    "/v1/sender/instances": {
      "get": {
        "operationId": "list_sender_instances",
        "summary": "Listar conexões",
        "description": "Consulte informações da sua conta. Requer acesso ao Disparador.",
        "tags": [
          "Disparador"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Consulta concluída. Exemplo fictício e resumido.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Conexao"
                      }
                    }
                  },
                  "required": [
                    "data"
                  ]
                },
                "example": {
                  "data": [
                    {
                      "id": "33333333-3333-3333-3333-333333333333",
                      "name": "Loja exemplo",
                      "status": "connected"
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Erro401"
          },
          "403": {
            "$ref": "#/components/responses/Erro403"
          },
          "429": {
            "$ref": "#/components/responses/Erro429"
          },
          "503": {
            "$ref": "#/components/responses/Erro503"
          }
        }
      }
    },
    "/v1/sender/campaigns": {
      "get": {
        "operationId": "list_sender_campaigns",
        "summary": "Listar campanhas",
        "description": "Consulte informações da sua conta. Requer acesso ao Disparador.",
        "tags": [
          "Disparador"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Limit"
          },
          {
            "$ref": "#/components/parameters/Offset"
          }
        ],
        "responses": {
          "200": {
            "description": "Consulta concluída. Exemplo fictício e resumido.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Campanha"
                      }
                    },
                    "limit": {
                      "type": "integer"
                    },
                    "offset": {
                      "type": "integer"
                    }
                  },
                  "required": [
                    "data",
                    "limit",
                    "offset"
                  ]
                },
                "example": {
                  "data": [
                    {
                      "id": "22222222-2222-2222-2222-222222222222",
                      "name": "Novidades da loja",
                      "status": "paused",
                      "total_contacts": 5,
                      "sent_count": 3,
                      "failed_count": 1,
                      "unknown_count": 1
                    }
                  ],
                  "limit": 50,
                  "offset": 0
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Erro401"
          },
          "403": {
            "$ref": "#/components/responses/Erro403"
          },
          "429": {
            "$ref": "#/components/responses/Erro429"
          },
          "503": {
            "$ref": "#/components/responses/Erro503"
          }
        }
      }
    },
    "/v1/sender/campaigns/{id}": {
      "get": {
        "operationId": "get_sender_campaign",
        "summary": "Consultar campanha",
        "description": "Consulte informações da sua conta. Requer acesso ao Disparador.",
        "tags": [
          "Disparador"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "Consulta concluída. Exemplo fictício e resumido.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Campanha"
                    }
                  },
                  "required": [
                    "data"
                  ]
                },
                "example": {
                  "data": {
                    "id": "22222222-2222-2222-2222-222222222222",
                    "name": "Novidades da loja",
                    "status": "paused",
                    "total_contacts": 5,
                    "sent_count": 3,
                    "failed_count": 1,
                    "unknown_count": 1
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Erro400"
          },
          "401": {
            "$ref": "#/components/responses/Erro401"
          },
          "403": {
            "$ref": "#/components/responses/Erro403"
          },
          "404": {
            "$ref": "#/components/responses/CampanhaNaoEncontrada"
          },
          "429": {
            "$ref": "#/components/responses/Erro429"
          },
          "503": {
            "$ref": "#/components/responses/Erro503"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ReadyzapKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "Chave criada em Integrações → Readyzap API."
      }
    },
    "parameters": {
      "Id": {
        "name": "id",
        "in": "path",
        "required": true,
        "description": "UUID retornado pela consulta de listagem.",
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      },
      "Limit": {
        "name": "limit",
        "in": "query",
        "description": "Quantidade de itens na página.",
        "schema": {
          "type": "integer",
          "minimum": 1,
          "maximum": 100,
          "default": 50
        }
      },
      "Offset": {
        "name": "offset",
        "in": "query",
        "description": "Quantidade de itens a pular.",
        "schema": {
          "type": "integer",
          "minimum": 0,
          "maximum": 100000,
          "default": 0
        }
      }
    },
    "schemas": {
      "Conta": {
        "type": "object",
        "properties": {
          "plan": {
            "type": [
              "string",
              "null"
            ]
          },
          "plan_status": {
            "type": [
              "string",
              "null"
            ]
          },
          "plan_expires_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "chip_limit": {
            "type": [
              "integer",
              "null"
            ]
          }
        }
      },
      "Chip": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "display_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "phone_number": {
            "type": [
              "string",
              "null"
            ]
          },
          "customer_status": {
            "type": [
              "string",
              "null"
            ]
          },
          "warming_phase": {
            "type": [
              "string",
              "null"
            ]
          },
          "warming_day": {
            "type": [
              "integer",
              "null"
            ]
          },
          "messages_sent_today": {
            "type": [
              "integer",
              "null"
            ]
          },
          "messages_received_today": {
            "type": [
              "integer",
              "null"
            ]
          },
          "groups_count": {
            "type": [
              "integer",
              "null"
            ]
          },
          "is_session_active": {
            "type": [
              "boolean",
              "null"
            ]
          },
          "created_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "Conexao": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": [
              "string",
              "null"
            ]
          },
          "phone": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "type": [
              "string",
              "null"
            ]
          },
          "messages_sent": {
            "type": [
              "integer",
              "null"
            ]
          },
          "created_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "Campanha": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "type": [
              "string",
              "null"
            ]
          },
          "total_contacts": {
            "type": [
              "integer",
              "null"
            ]
          },
          "sent_count": {
            "type": [
              "integer",
              "null"
            ]
          },
          "failed_count": {
            "type": [
              "integer",
              "null"
            ]
          },
          "unknown_count": {
            "type": [
              "integer",
              "null"
            ]
          },
          "scheduled_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "started_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "completed_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "created_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "Erro": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            },
            "required": [
              "code",
              "message"
            ]
          }
        },
        "required": [
          "error"
        ]
      }
    },
    "responses": {
      "Erro400": {
        "description": "ID malformado",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Erro"
            },
            "example": {
              "error": {
                "code": "invalid_id",
                "message": "id inválido."
              }
            }
          }
        }
      },
      "Erro401": {
        "description": "Chave ausente, inválida ou revogada",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Erro"
            },
            "example": {
              "error": {
                "code": "invalid_key",
                "message": "Chave inválida ou revogada."
              }
            }
          }
        }
      },
      "Erro403": {
        "description": "Acesso à API indisponível ou módulo exigido não habilitado",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Erro"
            },
            "example": {
              "error": {
                "code": "plan_not_allowed",
                "message": "A API está disponível nos planos Pro e Business ativos."
              }
            }
          }
        }
      },
      "Erro404": {
        "description": "Item não encontrado na sua conta",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Erro"
            },
            "example": {
              "error": {
                "code": "not_found",
                "message": "Chip não encontrado."
              }
            }
          }
        }
      },
      "Erro429": {
        "description": "Limite de requisições atingido",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Erro"
            },
            "example": {
              "error": {
                "code": "rate_limited",
                "message": "Limite de requisições por minuto atingido. Tente novamente no próximo minuto."
              }
            }
          }
        },
        "headers": {
          "Retry-After": {
            "description": "Tempo de espera em segundos.",
            "schema": {
              "type": "integer"
            },
            "example": 60
          }
        }
      },
      "Erro503": {
        "description": "Serviço temporariamente indisponível",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Erro"
            },
            "example": {
              "error": {
                "code": "unavailable",
                "message": "Serviço temporariamente indisponível."
              }
            }
          }
        }
      },
      "CampanhaNaoEncontrada": {
        "description": "Campanha não encontrada na sua conta",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Erro"
            },
            "example": {
              "error": {
                "code": "not_found",
                "message": "Campanha não encontrada."
              }
            }
          }
        }
      }
    }
  }
}
