#pragma once

#include <cstdio>
#include <sdbusplus/bus.hpp>
#include <string>
#include <vector>

#include "host-ipmid/ipmid-api.h"

/* Clearer way to represent the subcommand size. */
#define SUBCMD_SZ sizeof(uint8_t)

/*
 * These are the codes we return over IPMI when the host checks for the status
 * of the asynchronous verification call.
 */
enum VerifyCheckResponse
{
    running = 0x00,
    success = 0x01,
    failed = 0x02,
    other = 0x03,
};

/*
 * flashStartTransfer -- starts file upload.
 * flashDataBlock -- adds data to image file.
 * flashDataFinish -- closes the file.
 *
 * flashStartHash -- starts uploading hash.
 * flashDataHash -- adds data to the hash.
 * flashDataVerify -- triggers verification.
 *
 * flashAbort -- abort everything.
 *
 * flashVerifyCheck -- Check if the verification has completed.
 *
 * flashVersion -- Get the version of this OEM Handler.
 *
 * flashRequestRegion -- Request the physical address for decode (bridge)
 * flashDataExtBlock -- Provide image data via a bridge
 * flashHashExtData -- Provide hash data via a bridge
 */
enum FlashSubCmds
{
    /* Start a transfer. */
    flashStartTransfer = 0,
    /* Data block. */
    flashDataBlock = 1,
    /* Close file. */
    flashDataFinish = 2,

    /* Start a hash transfer. */
    flashStartHash = 3,
    /* Add data to the hash. */
    flashHashData = 4,
    /* Close out the hash file. */
    flashHashFinish = 5,

    /* Verify the flash image against the hast sent. */
    flashDataVerify = 6,

    /* Abort. */
    flashAbort = 7,

    /*
     * Check if the verification is ready and was successful.
     * If the response from the IPMI command is OK, check the
     * response bytes to know if it's ready or still computing,
     * or failed.
     */
    flashVerifyCheck = 8,

    flashVersion = 9,
    flashRequestRegion = 10,
    flashDataExtBlock = 11,
    flashHashExtData = 12,
    flashMapRegionLpc = 13,
};

/*
 * StartTransfer expects a basic structure providing some information.
 */
struct StartTx
{
    uint8_t cmd;
    uint32_t length; /* Maximum image length is 4GiB (little-endian) */
} __attribute__((packed));

struct ChunkHdr
{
    uint8_t cmd;
    uint32_t offset; /* 0-based write offset */
    uint8_t data[];
} __attribute__((packed));

class UpdateInterface
{
  public:
    virtual ~UpdateInterface() = default;

    /**
     * Prepare to receive a BMC image and then a signature.
     *
     * @param[in] length - the size of the flash image.
     * @return true on success, false otherwise.
     */
    virtual bool start(uint32_t length) = 0;

    /**
     * Attempt to write the bytes at the offset.
     *
     * @param[in] offset - the 0-based byte offset into the flash image.
     * @param[in] bytes - the bytes to write.
     * @return true on success, false otherwise.
     */
    virtual bool flashData(uint32_t offset,
                           const std::vector<uint8_t>& bytes) = 0;

    /**
     * Called to indicate the host is done sending the flash bytes.
     */
    virtual bool flashFinish() = 0;

    /**
     * Prepare to receive a BMC image signature.
     *
     * @param[in] length - length of signature in bytes.
     * @return true on success, false otherwise.
     */
    virtual bool startHash(uint32_t length) = 0;

    /**
     * Attempt to write the bytes at the offset.
     *
     * @param[in] offset - the 0-based byte offset into the flash image.
     * @param[in] bytes - the bytes to write.
     * @return true on success, false otherwise.
     */
    virtual bool hashData(uint32_t offset,
                          const std::vector<uint8_t>& bytes) = 0;

    /**
     * Called to indicate the host is done sending the hash bytes.
     */
    virtual bool hashFinish() = 0;

    /**
     * Kick off the flash image verification process.
     *
     * @return true if it was started succesfully.
     */
    virtual bool startDataVerification() = 0;

    /**
     * Attempt to abort everything.
     *
     * @return true if aborted, false if unable or failed.
     */
    virtual bool abortUpdate() = 0;

    /**
     * Check if the verification result is available and return.
     *
     * @return the verification response.
     */
    virtual VerifyCheckResponse checkVerify() = 0;
};

class FlashUpdate : public UpdateInterface
{
  public:
    FlashUpdate(sdbusplus::bus::bus&& bus, const std::string& stagingPath,
                const std::string& verifyPath, const std::string& hash = "") :
        bus(std::move(bus)),
        flashLength(0), flashFd(nullptr), tmpPath(stagingPath), hashLength(0),
        hashFd(nullptr), hashPath(hash), verifyPath(verifyPath){};
    ~FlashUpdate();

    FlashUpdate(const FlashUpdate&) = delete;
    FlashUpdate& operator=(const FlashUpdate&) = delete;
    FlashUpdate(FlashUpdate&&) = default;
    FlashUpdate& operator=(FlashUpdate&&) = default;

    bool start(uint32_t length) override;
    bool flashData(uint32_t offset, const std::vector<uint8_t>& bytes) override;
    bool flashFinish() override;

    bool startHash(uint32_t length) override;
    bool hashData(uint32_t offset, const std::vector<uint8_t>& bytes) override;
    bool hashFinish() override;

    bool startDataVerification() override;
    bool abortUpdate() override;
    VerifyCheckResponse checkVerify() override;

  private:
    /**
     * Attempt to write the bytes at the offset.
     *
     * @param[in] fd - the file stream pointer.
     * @param[in] offset - the 0-based byte offset into the flash image.
     * @param[in] bytes - the bytes to write.
     * @return true on success, false otherwise.
     */
    bool writeBlock(std::FILE* fd, uint32_t offset,
                    const std::vector<uint8_t>& bytes);

    /**
     * Tries to delete everything.
     */
    void deleteEverything();

    /**
     * Tries to close out everything.
     */
    void closeEverything();

    /**
     * Tries to close out and delete anything staged.
     */
    void abortEverything();

    /**
     * Open all staged file handles you expect to use.
     *
     * @return false on failure.
     */
    bool openEverything();

    /* A bus. */
    sdbusplus::bus::bus bus;

    /* The length of the flash image in bytes. */
    uint32_t flashLength;

    /* The file handle to the flash staging file. */
    std::FILE* flashFd;

    /* Where the bytes are written before verification. */
    const std::string tmpPath;

    /* The length of the hash in bytes. */
    uint32_t hashLength;

    /* The file handle to the hash file. */
    std::FILE* hashFd;

    /* Where we write the hash bytes.  Only required if your verification
     * process uses a separate signature.
     */
    const std::string hashPath;

    /* The path to read the status of the signature verification. */
    const std::string verifyPath;
};
