{
  "openapi": "3.1.0",
  "info": {
    "title": "db Higro Calc API",
    "version": "1.0.0",
    "description": "API para calcular equilíbrio higroscópico de grãos com requisição e resposta em JSON."
  },
  "servers": [
    {
      "url": "https://higrocalc.diegobittencourt.dev.br"
    }
  ],
  "paths": {
    "/api/health": {
      "get": {
        "summary": "Verifica a saúde do serviço",
        "responses": {
          "200": {
            "description": "Serviço online",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "example": true
                    },
                    "service": {
                      "type": "string",
                      "example": "db Higro Calc"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/grains": {
      "get": {
        "summary": "Lista os grãos suportados",
        "responses": {
          "200": {
            "description": "Lista de grãos disponíveis",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "grains": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Grain"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/calculate": {
      "post": {
        "summary": "Calcula o equilíbrio higroscópico",
        "description": "Recebe o identificador do grão, a temperatura ambiente e a umidade relativa do ar.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CalculationRequest"
              },
              "examples": {
                "corn": {
                  "summary": "Exemplo com milho",
                  "value": {
                    "grain": "Corn",
                    "ta": 25,
                    "ur": 60
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Resultado calculado com sucesso",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CalculationResponse"
                },
                "examples": {
                  "success": {
                    "summary": "Resposta com sucesso",
                    "value": {
                      "ok": true,
                      "grain": "Corn",
                      "grainLabel": "Milho",
                      "ta": 25,
                      "ur": 60,
                      "result": 13.8,
                      "resultLabel": "13.8% b.u."
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Dados inválidos",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "examples": {
                  "rangeError": {
                    "summary": "Campo fora da faixa",
                    "value": {
                      "ok": false,
                      "error": "Umidade relativa deve estar entre 1 e 99."
                    }
                  }
                }
              }
            }
          },
          "413": {
            "description": "Payload muito grande",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Muitas requisições",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "examples": {
                  "rateLimit": {
                    "summary": "Limite temporário",
                    "value": {
                      "error": "Limite de requisicoes excedido. Tente novamente em alguns minutos."
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Grain": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "Soy"
          },
          "label": {
            "type": "string",
            "example": "Soja"
          }
        }
      },
      "CalculationRequest": {
        "type": "object",
        "required": [
          "grain",
          "ta",
          "ur"
        ],
        "properties": {
          "grain": {
            "type": "string",
        "description": "Identificador do grão desejado.",
            "example": "Soy"
          },
          "ta": {
            "type": "number",
            "description": "Temperatura ambiente em graus Celsius.",
            "minimum": 1,
            "maximum": 50,
            "example": 25
          },
          "ur": {
            "type": "number",
            "description": "Umidade relativa do ar em porcentagem.",
            "minimum": 1,
            "maximum": 99,
            "example": 60
          }
        }
      },
      "CalculationResponse": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean",
            "example": true
          },
          "grain": {
            "type": "string",
            "example": "Soy"
          },
          "grainLabel": {
            "type": "string",
            "example": "Soja"
          },
          "ta": {
            "type": "number",
            "example": 25
          },
          "ur": {
            "type": "number",
            "example": 60
          },
          "result": {
            "type": "number",
            "example": 10.5
          },
          "resultLabel": {
            "type": "string",
            "example": "10.5% b.u."
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean",
            "example": false
          },
          "error": {
            "type": "string",
            "example": "Grao invalido."
          }
        }
      }
    }
  }
}
