#ifndef MyController_hpp
#define MyController_hpp

#include "dto/DTOs.hpp"
#include "oatpp/macro/codegen.hpp"
#include "oatpp/macro/component.hpp"
#include "oatpp/network/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::ClientConnectionProvider::createShared(
                {"https://"
                 "g904262e6628ef4-rt9s33uedog5sypd.adb.eu-madrid-1."
                 "oraclecloudapps.com/ords/admin/api",
                 80});
        auto requestExecutor =
            oatpp::web::client::HttpRequestExecutor::createShared(
                connectionProvider);
        auto request = requestExecutor->execute("GET", "/embalses");
        if (request->getStatusCode() == 200) {
            auto responseStream = request->getBody();
            oatpp::data::stream::BufferOutputStream buffer;
            responseStream->readToStream(&buffer);
            OATPP_LOGd("MyController", "Response: %s",
                       buffer.toString()->c_str());
            return createResponse(Status::CODE_200, buffer.toString());
        }
    }

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

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

#endif /* MyController_hpp */
