#ifndef __CATALOG_H__
#define __CATALOG_H__

#include <climits>
#include <cstdint>
#include <string>
#include <vector>

#include "CatalogItem.h"


class Catalog
{
public:

    Catalog();

    ~Catalog();

    int load(
        char* filePath,
        char* passwordBuffer,
        uint32_t passwordBufferSize,
        float* complete);

    inline bool getLoaded() const
    {
        return m_loaded;
    }

    inline std::vector<CatalogItem>::iterator begin()
    {
        return m_catalog.begin();
    }

    inline std::vector<CatalogItem>::iterator end()
    {
        return m_catalog.end();
    }

    void setAllVisible();

    void filter(const std::string& criteria);

    static const char* errToString(int err)
    {
        switch (err)
        {
            case ERR_PWHASH_OUT_OF_MEMORY:
                return "pwhash: out of memory";

            case ERR_DECRYPT_INCOMPLETE_HEADER:
                return "decrypt: incomplete header";

            case ERR_DECRYPT_CORRUPTED_CHUNK:
                return "decrypt: corrupted chunk";

            case ERR_DECRYPT_PREMATURE_END:
                return "decrypt: premature end of file";

            default:
                return "unknown error";
        }
    }


private:

    static inline const int ERR_PWHASH_OUT_OF_MEMORY         = INT_MIN + 19;
    static inline const int ERR_DECRYPT_INCOMPLETE_HEADER    = INT_MIN + 20;
    static inline const int ERR_DECRYPT_CORRUPTED_CHUNK      = INT_MIN + 21;
    static inline const int ERR_DECRYPT_PREMATURE_END        = INT_MIN + 22;

    void sort();

    bool m_loaded;
    std::vector<CatalogItem> m_catalog;

};


#endif // __CATALOG_H__