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