// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "eth.hpp"

#include "commands.hpp"
#include "handler.hpp"

#include <cstdint>
#include <cstring>
#include <ipmid/api-types.hpp>
#include <span>
#include <string>
#include <tuple>
#include <vector>

namespace google
{
namespace ipmi
{

// TOOD(venture): The ipmid.h has this macro, which is a header we
// can't normally access.
#ifndef MAX_IPMI_BUFFER
#define MAX_IPMI_BUFFER 64
#endif

Resp getEthDevice(std::span<const uint8_t> data,
                  const HandlerInterface* handler)
{
    std::tuple<std::uint8_t, std::string> details =
        handler->getEthDetails(std::string(data.begin(), data.end()));

    std::string device = std::get<1>(details);
    if (device.length() == 0)
    {
        std::fprintf(stderr, "Invalid eth string\n");
        return ::ipmi::responseReqDataLenInvalid();
    }

    if ((sizeof(struct EthDeviceReply) + device.length()) > MAX_IPMI_BUFFER)
    {
        std::fprintf(stderr, "Response would overflow response buffer\n");
        return ::ipmi::responseRetBytesUnavailable();
    }

    std::vector<std::uint8_t> reply;
    reply.reserve(device.length() + sizeof(struct EthDeviceReply));
    reply.emplace_back(std::get<0>(details));                /* channel */
    reply.emplace_back(device.length());                     /* ifNameLength */
    reply.insert(reply.end(), device.begin(), device.end()); /* name */

    return ::ipmi::responseSuccess(SysOEMCommands::SysGetEthDevice, reply);
}

} // namespace ipmi
} // namespace google
