#include "ffdc_file.hpp"

#include <errno.h> // for errno
#include <fcntl.h> // for open()
#include <fmt/format.h>
#include <string.h>    // for strerror()
#include <sys/stat.h>  // for open()
#include <sys/types.h> // for open()

#include <phosphor-logging/log.hpp>

#include <stdexcept>
#include <string>

namespace watchdog
{
namespace dump
{
using namespace phosphor::logging;

FFDCFile::FFDCFile(const json& calloutDataObject) :
    calloutData(calloutDataObject.dump())
{
    prepareFFDCFile();
}

FFDCFile::~FFDCFile()
{
    // Close file descriptor.  Does nothing if descriptor was already closed.
    if (descriptor.close() == -1)
    {
        log<level::ERR>(fmt::format("Unable to close FFDC file: errormsg({})",
                                    strerror(errno))
                            .c_str());
    }

    // Delete temporary file.  Does nothing if file was already deleted.
    tempFile.remove();
}

void FFDCFile::prepareFFDCFile()
{
    // Open the temporary file for both reading and writing
    int fd = open(tempFile.getPath().c_str(), O_RDWR);
    if (fd == -1)
    {
        throw std::runtime_error{std::string{"Unable to open FFDC file: "} +
                                 strerror(errno)};
    }

    ssize_t rc = write(fd, calloutData.c_str(), calloutData.size());

    if (rc == -1)
    {
        log<level::ERR>(fmt::format("Failed to write callout info "
                                    "in file({}), errorno({}), errormsg({})",
                                    tempFile.getPath().c_str(), errno,
                                    strerror(errno))
                            .c_str());
        throw std::runtime_error("Failed to write phalPELCallouts info");
    }
    else if (rc != static_cast<ssize_t>(calloutData.size()))
    {
        log<level::WARNING>(fmt::format("Could not write all callout "
                                        "info in file({}), written byte({}) "
                                        "and total byte({})",
                                        tempFile.getPath().c_str(), rc,
                                        calloutData.size())
                                .c_str());
    }

    int retCode = lseek(fd, 0, SEEK_SET);

    if (retCode == -1)
    {
        log<level::ERR>(
            fmt::format("Failed to seek file postion to the beginning"
                        "in file({}), errorno({}) "
                        "and errormsg({})",
                        tempFile.getPath().c_str(), errno, strerror(errno))
                .c_str());
        throw std::runtime_error(
            "Failed to seek file postion to the beginning of the file");
    }

    // Store file descriptor in FileDescriptor object
    descriptor.set(fd);
}

} // namespace dump
} // namespace watchdog
