// 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 "machine_name.hpp"

#include "commands.hpp"
#include "errors.hpp"

#include <ipmid/api-types.hpp>
#include <stdplus/print.hpp>

#include <cstddef>
#include <cstdio>
#include <cstring>
#include <optional>
#include <span>
#include <string>
#include <vector>

namespace google
{
namespace ipmi
{

Resp getMachineName(std::span<const uint8_t>, HandlerInterface* handler)
{
    static std::optional<std::string> machineName;
    if (!machineName)
    {
        try
        {
            machineName = handler->getMachineName();
        }
        catch (const IpmiException& e)
        {
            return ::ipmi::response(e.getIpmiError());
        }
    }

    size_t len = sizeof(struct GetMachineNameReply) + machineName->size();
    if (len > MAX_IPMI_BUFFER)
    {
        stdplus::print(stderr, "Response would overflow response buffer\n");
        return ::ipmi::responseInvalidCommand();
    }

    std::vector<std::uint8_t> reply;
    reply.reserve(len);
    reply.emplace_back(machineName->size()); /* machineNameLength */
    reply.insert(reply.end(), machineName->begin(),
                 machineName->end());        /* machineName */

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

} // namespace ipmi
} // namespace google
