// Copyright (c) ZeroC, Inc.

// slice2cpp version 3.8.1
// <auto-generated>Generated from Slice file 'PropertiesAdmin.ice'.</auto-generated>

#ifndef ICE_API_EXPORTS
#   define ICE_API_EXPORTS
#endif
#define ICE_BUILDING_GENERATED_CODE

#include "Ice/PropertiesAdmin.h"
#include <Ice/AsyncResponseHandler.h>
#include <Ice/DefaultSliceLoader.h>
#include <Ice/OutgoingAsync.h>
#include <algorithm>
#include <array>

#if defined(_MSC_VER)
#   pragma warning(disable : 4458) // declaration of ... hides class member
#   pragma warning(disable : 4996) // ... was declared deprecated
#elif defined(__clang__)
#   pragma clang diagnostic ignored "-Wshadow"
#   pragma clang diagnostic ignored "-Wdeprecated-declarations"
#elif defined(__GNUC__)
#   pragma GCC diagnostic ignored "-Wshadow"
#   pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif

#ifndef ICE_DISABLE_VERSION
#   if ICE_INT_VERSION / 100 != 308
#       error Ice version mismatch!
#   endif
#   if ICE_INT_VERSION % 100 >= 50
#       error Beta header file detected
#   endif
#   if ICE_INT_VERSION % 100 < 1
#       error Ice patch level mismatch!
#   endif
#endif

Ice::PropertiesAdminPrx::~PropertiesAdminPrx() = default;

std::string
Ice::PropertiesAdminPrx::getProperty(std::string_view iceP_key, const Ice::Context& context) const
{
    return IceInternal::makePromiseOutgoing<std::string>(true, this, &PropertiesAdminPrx::_iceI_getProperty, iceP_key, context).get();
}

std::future<std::string>
Ice::PropertiesAdminPrx::getPropertyAsync(std::string_view iceP_key, const Ice::Context& context) const
{
    return IceInternal::makePromiseOutgoing<std::string>(false, this, &PropertiesAdminPrx::_iceI_getProperty, iceP_key, context);
}

std::function<void()>
Ice::PropertiesAdminPrx::getPropertyAsync(std::string_view iceP_key, std::function<void(std::string)> response, std::function<void(std::exception_ptr)> exception, std::function<void(bool)> sent, const Ice::Context& context) const
{
    return IceInternal::makeLambdaOutgoing<std::string>(std::move(response), std::move(exception), std::move(sent), this, &Ice::PropertiesAdminPrx::_iceI_getProperty, iceP_key, context);
}

void
Ice::PropertiesAdminPrx::_iceI_getProperty(const std::shared_ptr<IceInternal::OutgoingAsyncT<std::string>>& outAsync, std::string_view iceP_key, const Ice::Context& context) const
{
    static constexpr std::string_view operationName = "getProperty";

    _checkTwowayOnly(operationName);
    outAsync->invoke(
        operationName,
        Ice::OperationMode::Normal,
        std::nullopt,
        context,
        [&](Ice::OutputStream* ostr)
        {
            ostr->writeAll(iceP_key);
        },
        nullptr);
}

::Ice::PropertyDict
Ice::PropertiesAdminPrx::getPropertiesForPrefix(std::string_view iceP_prefix, const Ice::Context& context) const
{
    return IceInternal::makePromiseOutgoing<PropertyDict>(true, this, &PropertiesAdminPrx::_iceI_getPropertiesForPrefix, iceP_prefix, context).get();
}

std::future<::Ice::PropertyDict>
Ice::PropertiesAdminPrx::getPropertiesForPrefixAsync(std::string_view iceP_prefix, const Ice::Context& context) const
{
    return IceInternal::makePromiseOutgoing<PropertyDict>(false, this, &PropertiesAdminPrx::_iceI_getPropertiesForPrefix, iceP_prefix, context);
}

std::function<void()>
Ice::PropertiesAdminPrx::getPropertiesForPrefixAsync(std::string_view iceP_prefix, std::function<void(::Ice::PropertyDict)> response, std::function<void(std::exception_ptr)> exception, std::function<void(bool)> sent, const Ice::Context& context) const
{
    return IceInternal::makeLambdaOutgoing<PropertyDict>(std::move(response), std::move(exception), std::move(sent), this, &Ice::PropertiesAdminPrx::_iceI_getPropertiesForPrefix, iceP_prefix, context);
}

void
Ice::PropertiesAdminPrx::_iceI_getPropertiesForPrefix(const std::shared_ptr<IceInternal::OutgoingAsyncT<PropertyDict>>& outAsync, std::string_view iceP_prefix, const Ice::Context& context) const
{
    static constexpr std::string_view operationName = "getPropertiesForPrefix";

    _checkTwowayOnly(operationName);
    outAsync->invoke(
        operationName,
        Ice::OperationMode::Normal,
        std::nullopt,
        context,
        [&](Ice::OutputStream* ostr)
        {
            ostr->writeAll(iceP_prefix);
        },
        nullptr);
}

void
Ice::PropertiesAdminPrx::setProperties(const PropertyDict& iceP_newProperties, const Ice::Context& context) const
{
    IceInternal::makePromiseOutgoing<void>(true, this, &PropertiesAdminPrx::_iceI_setProperties, iceP_newProperties, context).get();
}

std::future<void>
Ice::PropertiesAdminPrx::setPropertiesAsync(const PropertyDict& iceP_newProperties, const Ice::Context& context) const
{
    return IceInternal::makePromiseOutgoing<void>(false, this, &PropertiesAdminPrx::_iceI_setProperties, iceP_newProperties, context);
}

std::function<void()>
Ice::PropertiesAdminPrx::setPropertiesAsync(const PropertyDict& iceP_newProperties, std::function<void()> response, std::function<void(std::exception_ptr)> exception, std::function<void(bool)> sent, const Ice::Context& context) const
{
    return IceInternal::makeLambdaOutgoing<void>(std::move(response), std::move(exception), std::move(sent), this, &Ice::PropertiesAdminPrx::_iceI_setProperties, iceP_newProperties, context);
}

void
Ice::PropertiesAdminPrx::_iceI_setProperties(const std::shared_ptr<IceInternal::OutgoingAsyncT<void>>& outAsync, const PropertyDict& iceP_newProperties, const Ice::Context& context) const
{
    static constexpr std::string_view operationName = "setProperties";

    outAsync->invoke(
        operationName,
        Ice::OperationMode::Normal,
        std::nullopt,
        context,
        [&](Ice::OutputStream* ostr)
        {
            ostr->writeAll(iceP_newProperties);
        },
        nullptr);
}

const char*
Ice::PropertiesAdminPrx::ice_staticId() noexcept
{
    return "::Ice::PropertiesAdmin";
}

void
Ice::PropertiesAdmin::dispatch(Ice::IncomingRequest& request, std::function<void(Ice::OutgoingResponse)> sendResponse)
{
    static constexpr std::array<std::string_view, 7> allOperations{"getPropertiesForPrefix", "getProperty", "ice_id", "ice_ids", "ice_isA", "ice_ping", "setProperties"};

    const Ice::Current& current = request.current();
    auto r = std::equal_range(allOperations.begin(), allOperations.end(), current.operation); // NOLINT(modernize-use-ranges)
    if (r.first == r.second)
    {
        sendResponse(Ice::makeOutgoingResponse(std::make_exception_ptr(Ice::OperationNotExistException{__FILE__, __LINE__}), current));
        return;
    }

    switch (r.first - allOperations.begin())
    {
        case 0:
        {
            _iceD_getPropertiesForPrefix(request, std::move(sendResponse));
            break;
        }
        case 1:
        {
            _iceD_getProperty(request, std::move(sendResponse));
            break;
        }
        case 2:
        {
            _iceD_ice_id(request, std::move(sendResponse));
            break;
        }
        case 3:
        {
            _iceD_ice_ids(request, std::move(sendResponse));
            break;
        }
        case 4:
        {
            _iceD_ice_isA(request, std::move(sendResponse));
            break;
        }
        case 5:
        {
            _iceD_ice_ping(request, std::move(sendResponse));
            break;
        }
        case 6:
        {
            _iceD_setProperties(request, std::move(sendResponse));
            break;
        }
        default:
        {
            assert(false);
            sendResponse(Ice::makeOutgoingResponse(std::make_exception_ptr(Ice::OperationNotExistException{__FILE__, __LINE__}), current));
        }
    }
}

std::vector<std::string>
Ice::PropertiesAdmin::ice_ids(const Ice::Current&) const
{
    static const std::vector<std::string> allTypeIds = {"::Ice::Object", "::Ice::PropertiesAdmin"};
    return allTypeIds;
}

std::string
Ice::PropertiesAdmin::ice_id(const Ice::Current&) const
{
    return std::string{ice_staticId()};
}

void
Ice::PropertiesAdmin::_iceD_getProperty(
    Ice::IncomingRequest& request,
    std::function<void(Ice::OutgoingResponse)> sendResponse) // NOLINT(performance-unnecessary-value-param)
{
    checkNonIdempotent(request.current());
    auto istr = &request.inputStream();
    istr->startEncapsulation();
    std::string iceP_key;
    istr->readAll(iceP_key);
    istr->endEncapsulation();
    const std::string ret = this->getProperty(std::move(iceP_key), request.current());
    sendResponse(Ice::makeOutgoingResponse([&](Ice::OutputStream* ostr)
        {
            ostr->writeAll(ret);
        },
        request.current()));
}

void
Ice::PropertiesAdmin::_iceD_getPropertiesForPrefix(
    Ice::IncomingRequest& request,
    std::function<void(Ice::OutgoingResponse)> sendResponse) // NOLINT(performance-unnecessary-value-param)
{
    checkNonIdempotent(request.current());
    auto istr = &request.inputStream();
    istr->startEncapsulation();
    std::string iceP_prefix;
    istr->readAll(iceP_prefix);
    istr->endEncapsulation();
    const PropertyDict ret = this->getPropertiesForPrefix(std::move(iceP_prefix), request.current());
    sendResponse(Ice::makeOutgoingResponse([&](Ice::OutputStream* ostr)
        {
            ostr->writeAll(ret);
        },
        request.current()));
}

void
Ice::PropertiesAdmin::_iceD_setProperties(
    Ice::IncomingRequest& request,
    std::function<void(Ice::OutgoingResponse)> sendResponse) // NOLINT(performance-unnecessary-value-param)
{
    checkNonIdempotent(request.current());
    auto istr = &request.inputStream();
    istr->startEncapsulation();
    PropertyDict iceP_newProperties;
    istr->readAll(iceP_newProperties);
    istr->endEncapsulation();
    this->setProperties(std::move(iceP_newProperties), request.current());
    sendResponse(Ice::makeEmptyOutgoingResponse(request.current()));
}

const char*
Ice::PropertiesAdmin::ice_staticId() noexcept
{
    return "::Ice::PropertiesAdmin";
}

void
Ice::AsyncPropertiesAdmin::dispatch(Ice::IncomingRequest& request, std::function<void(Ice::OutgoingResponse)> sendResponse)
{
    static constexpr std::array<std::string_view, 7> allOperations{"getPropertiesForPrefix", "getProperty", "ice_id", "ice_ids", "ice_isA", "ice_ping", "setProperties"};

    const Ice::Current& current = request.current();
    auto r = std::equal_range(allOperations.begin(), allOperations.end(), current.operation); // NOLINT(modernize-use-ranges)
    if (r.first == r.second)
    {
        sendResponse(Ice::makeOutgoingResponse(std::make_exception_ptr(Ice::OperationNotExistException{__FILE__, __LINE__}), current));
        return;
    }

    switch (r.first - allOperations.begin())
    {
        case 0:
        {
            _iceD_getPropertiesForPrefix(request, std::move(sendResponse));
            break;
        }
        case 1:
        {
            _iceD_getProperty(request, std::move(sendResponse));
            break;
        }
        case 2:
        {
            _iceD_ice_id(request, std::move(sendResponse));
            break;
        }
        case 3:
        {
            _iceD_ice_ids(request, std::move(sendResponse));
            break;
        }
        case 4:
        {
            _iceD_ice_isA(request, std::move(sendResponse));
            break;
        }
        case 5:
        {
            _iceD_ice_ping(request, std::move(sendResponse));
            break;
        }
        case 6:
        {
            _iceD_setProperties(request, std::move(sendResponse));
            break;
        }
        default:
        {
            assert(false);
            sendResponse(Ice::makeOutgoingResponse(std::make_exception_ptr(Ice::OperationNotExistException{__FILE__, __LINE__}), current));
        }
    }
}

std::vector<std::string>
Ice::AsyncPropertiesAdmin::ice_ids(const Ice::Current&) const
{
    static const std::vector<std::string> allTypeIds = {"::Ice::Object", "::Ice::PropertiesAdmin"};
    return allTypeIds;
}

std::string
Ice::AsyncPropertiesAdmin::ice_id(const Ice::Current&) const
{
    return std::string{ice_staticId()};
}

void
Ice::AsyncPropertiesAdmin::_iceD_getProperty(
    Ice::IncomingRequest& request,
    std::function<void(Ice::OutgoingResponse)> sendResponse)
{
    checkNonIdempotent(request.current());
    auto istr = &request.inputStream();
    istr->startEncapsulation();
    std::string iceP_key;
    istr->readAll(iceP_key);
    istr->endEncapsulation();
    auto responseHandler = std::make_shared<IceInternal::AsyncResponseHandler>(std::move(sendResponse), request.current());
    auto responseCb = [responseHandler](std::string_view ret)
    {
        responseHandler->sendResponse(
            [&](Ice::OutputStream* ostr)
            {
                ostr->writeAll(ret);
            });
    };
    try
    {
        this->getPropertyAsync(std::move(iceP_key), std::move(responseCb), [responseHandler](std::exception_ptr ex) { responseHandler->sendException(ex); }, responseHandler->current());
    }
    catch (...)
    {
        responseHandler->sendException(std::current_exception());
    }
}

void
Ice::AsyncPropertiesAdmin::_iceD_getPropertiesForPrefix(
    Ice::IncomingRequest& request,
    std::function<void(Ice::OutgoingResponse)> sendResponse)
{
    checkNonIdempotent(request.current());
    auto istr = &request.inputStream();
    istr->startEncapsulation();
    std::string iceP_prefix;
    istr->readAll(iceP_prefix);
    istr->endEncapsulation();
    auto responseHandler = std::make_shared<IceInternal::AsyncResponseHandler>(std::move(sendResponse), request.current());
    auto responseCb = [responseHandler](const PropertyDict& ret)
    {
        responseHandler->sendResponse(
            [&](Ice::OutputStream* ostr)
            {
                ostr->writeAll(ret);
            });
    };
    try
    {
        this->getPropertiesForPrefixAsync(std::move(iceP_prefix), std::move(responseCb), [responseHandler](std::exception_ptr ex) { responseHandler->sendException(ex); }, responseHandler->current());
    }
    catch (...)
    {
        responseHandler->sendException(std::current_exception());
    }
}

void
Ice::AsyncPropertiesAdmin::_iceD_setProperties(
    Ice::IncomingRequest& request,
    std::function<void(Ice::OutgoingResponse)> sendResponse)
{
    checkNonIdempotent(request.current());
    auto istr = &request.inputStream();
    istr->startEncapsulation();
    PropertyDict iceP_newProperties;
    istr->readAll(iceP_newProperties);
    istr->endEncapsulation();
    auto responseHandler = std::make_shared<IceInternal::AsyncResponseHandler>(std::move(sendResponse), request.current());
    try
    {
        this->setPropertiesAsync(std::move(iceP_newProperties), [responseHandler] { responseHandler->sendEmptyResponse(); }, [responseHandler](std::exception_ptr ex) { responseHandler->sendException(ex); }, responseHandler->current());
    }
    catch (...)
    {
        responseHandler->sendException(std::current_exception());
    }
}

const char*
Ice::AsyncPropertiesAdmin::ice_staticId() noexcept
{
    return "::Ice::PropertiesAdmin";
}
