#pragma once
#include <boost/asio/ip/address.hpp>
#include <boost/asio/ip/basic_endpoint.hpp>
#include <sdbusplus/message.hpp>

#include <charconv>
#include <iostream>
#include <memory>

namespace crow
{

namespace async_resolve
{

class Resolver
{
  public:
    Resolver() = default;

    ~Resolver() = default;

    Resolver(const Resolver&) = delete;
    Resolver(Resolver&&) = delete;
    Resolver& operator=(const Resolver&) = delete;
    Resolver& operator=(Resolver&&) = delete;

    template <typename ResolveHandler>
    void asyncResolve(const std::string& host, uint16_t port,
                      ResolveHandler&& handler)
    {
        BMCWEB_LOG_DEBUG << "Trying to resolve: " << host << ":" << port;
        uint64_t flag = 0;
        crow::connections::systemBus->async_method_call(
            [host, port, handler{std::forward<ResolveHandler>(handler)}](
                const boost::system::error_code ec,
                const std::vector<
                    std::tuple<int32_t, int32_t, std::vector<uint8_t>>>& resp,
                const std::string& hostName, const uint64_t flagNum) {
            std::vector<boost::asio::ip::tcp::endpoint> endpointList;
            if (ec)
            {
                BMCWEB_LOG_ERROR << "Resolve failed: " << ec.message();
                handler(ec, endpointList);
                return;
            }
            BMCWEB_LOG_DEBUG << "ResolveHostname returned: " << hostName << ":"
                             << flagNum;
            // Extract the IP address from the response
            for (auto resolveList : resp)
            {
                std::vector<uint8_t> ipAddress = std::get<2>(resolveList);
                boost::asio::ip::tcp::endpoint endpoint;
                if (ipAddress.size() == 4) // ipv4 address
                {
                    BMCWEB_LOG_DEBUG << "ipv4 address";
                    boost::asio::ip::address_v4 ipv4Addr(
                        {ipAddress[0], ipAddress[1], ipAddress[2],
                         ipAddress[3]});
                    endpoint.address(ipv4Addr);
                }
                else if (ipAddress.size() == 16) // ipv6 address
                {
                    BMCWEB_LOG_DEBUG << "ipv6 address";
                    boost::asio::ip::address_v6 ipv6Addr(
                        {ipAddress[0], ipAddress[1], ipAddress[2], ipAddress[3],
                         ipAddress[4], ipAddress[5], ipAddress[6], ipAddress[7],
                         ipAddress[8], ipAddress[9], ipAddress[10],
                         ipAddress[11], ipAddress[12], ipAddress[13],
                         ipAddress[14], ipAddress[15]});
                    endpoint.address(ipv6Addr);
                }
                else
                {
                    BMCWEB_LOG_ERROR
                        << "Resolve failed to fetch the IP address";
                    handler(ec, endpointList);
                    return;
                }
                endpoint.port(port);
                BMCWEB_LOG_DEBUG << "resolved endpoint is : " << endpoint;
                endpointList.push_back(endpoint);
            }
            // All the resolved data is filled in the endpointList
            handler(ec, endpointList);
            },
            "org.freedesktop.resolve1", "/org/freedesktop/resolve1",
            "org.freedesktop.resolve1.Manager", "ResolveHostname", 0, host,
            AF_UNSPEC, flag);
    }
};

} // namespace async_resolve
} // namespace crow
