/*
// Copyright (c) 2024 Hewlett Packard Enterprise
//
// 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_context.hpp"

#include <filesystem>
#include <fstream>

void MachineContext::populateFromDeviceTree()
{
    std::string nodeVal;
    std::ifstream vpdStream(nodeBasePath + std::string("model"));
    if (vpdStream && std::getline(vpdStream, nodeVal))
    {
        MachineContext::Asset::model(nodeVal);
        vpdStream.close();
    }

    vpdStream.open(nodeBasePath + std::string("serial-number"));
    if (vpdStream && std::getline(vpdStream, nodeVal))
    {
        MachineContext::Asset::serial_number(nodeVal);
        vpdStream.close();
    }
};

bool MachineContext::keyNodeExists()
{
    std::filesystem::path nodePath{nodeBasePath + std::string("model")};

    return std::filesystem::exists(nodePath);
};
