// 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 <cstddef>
#include <cstdio>
#include <cstring>
#include <ipmid/api-types.hpp>
#include <optional>
#include <string>
#include <vector>

namespace google
{
namespace ipmi
{

Resp getMachineName(const std::vector<std::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)
    {
        std::fprintf(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
