#pragma once

#include <cstdio>
#include <string>
#include <vector>

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

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

/*
 * 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;
};

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

    FlashUpdate(const FlashUpdate&) = default;
    FlashUpdate& operator=(const FlashUpdate&) = default;
    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;

  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 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();

    /* 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;
};
