// 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 <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)
    {
        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
