#include "zero.hpp"

#include "erase.hpp"

#include <phosphor-logging/lg2.hpp>
#include <stdplus/fd/create.hpp>
#include <stdplus/fd/managed.hpp>
#include <xyz/openbmc_project/Common/error.hpp>

#include <array>
#include <span>

namespace estoraged
{

using sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
using stdplus::fd::ManagedFd;

void Zero::writeZero(const uint64_t driveSize)
{

    ManagedFd fd =
        stdplus::fd::open(devPath, stdplus::fd::OpenAccess::WriteOnly);

    uint64_t currentIndex = 0;
    const std::array<const std::byte, blockSize> blockOfZeros{};

    while (currentIndex < driveSize)
    {
        uint32_t writeSize = currentIndex + blockSize < driveSize
                                 ? blockSize
                                 : driveSize - currentIndex;
        try
        {
            fd.write({blockOfZeros.data(), writeSize});
        }
        catch (...)
        {
            lg2::error("Estoraged erase zeros unable to write size",
                       "REDFISH_MESSAGE_ID",
                       std::string("eStorageD.1.0.EraseFailure"));
            throw InternalFailure();
        }
        currentIndex += writeSize;
    }
}

void Zero::verifyZero(uint64_t driveSize)
{
    ManagedFd fd =
        stdplus::fd::open(devPath, stdplus::fd::OpenAccess::ReadOnly);

    uint64_t currentIndex = 0;
    std::array<std::byte, blockSize> readArr{};
    const std::array<const std::byte, blockSize> blockOfZeros{};

    while (currentIndex < driveSize)
    {
        uint32_t readSize = currentIndex + blockSize < driveSize
                                ? blockSize
                                : driveSize - currentIndex;
        try
        {
            fd.read({readArr.data(), readSize});
        }
        catch (...)
        {
            lg2::error("Estoraged erase zeros block unable to read size",
                       "REDFISH_MESSAGE_ID",
                       std::string("eStorageD.1.0.EraseFailure"));
            throw InternalFailure();
        }
        if (memcmp(readArr.data(), blockOfZeros.data(), readSize) != 0)
        {
            lg2::error("Estoraged erase zeros block is not zero",
                       "REDFISH_MESSAGE_ID",
                       std::string("eStorageD.1.0.EraseFailure"));
            throw InternalFailure();
        }
        currentIndex += readSize;
    }
}

} // namespace estoraged
