#ifndef MyController_hpp
#define MyController_hpp

#include <oatpp/web/protocol/http/Http.hpp>

#include "dto/DTOs.hpp"
#include "oatpp/macro/codegen.hpp"
#include "oatpp/macro/component.hpp"
#include "oatpp/network/tcp/client/ConnectionProvider.hpp"
#include "oatpp/web/client/HttpRequestExecutor.hpp"
#include "oatpp/web/protocol/http/outgoing/Request.hpp"
#include "oatpp/web/server/api/ApiController.hpp"

#include OATPP_CODEGEN_BEGIN(ApiController)  //<-- Begin Codegen

/**
 * Sample Api Controller.
 */
class MyController : public oatpp::web::server::api::ApiController {
   public:
    /**
     * Constructor with object mapper.
     * @param apiContentMappers - mappers used to serialize/deserialize DTOs.
     */
    MyController(OATPP_COMPONENT(
        std::shared_ptr<oatpp::web::mime::ContentMappers>, apiContentMappers))
        : oatpp::web::server::api::ApiController(apiContentMappers) {}

   public:
    ENDPOINT("GET", "/", root) {
        auto dto = Embalses::createShared();
        auto connectionProvider =
            oatpp::network::tcp::client::ConnectionProvider::createShared(
                {"https://"
                 "g904262e6628ef4-rt9s33uedog5sypd.adb.eu-madrid-1."
                 "oraclecloudapps.com/ords/admin/api",
                 443});
        auto requestExecutor =
            oatpp::web::client::HttpRequestExecutor::createShared(
                connectionProvider);
        auto headers =
            oatpp::web::protocol::http::Protocol::Headers::createShared();
        auto request = requestExecutor->executeOnce(
            "GET",
            "https://"
            "g904262e6628ef4-rt9s33uedog5sypd.adb.eu-madrid-1.oraclecloudapps."
            "com/ords/admin/api/embalses",
            headers, nullptr);
        if (request->getStatusCode() == 200) {
            auto responseStream = request->readBodyToString();
            oatpp::data::stream::BufferOutputStream buffer;
            // responseStream->readToStream(&buffer);
            OATPP_LOGd("MyController", "Response: %s", responseStream);
            return createResponse(Status::CODE_200, buffer.toString());
        }
    }

    // TODO Insert Your endpoints here !!!
};

#include OATPP_CODEGEN_END(ApiController)  //<-- End Codegen

#endif /* MyController_hpp */
