#pragma once

#include "Array.h"
#include "ReferenceCounter.h"

namespace Framework
{
    class Text;
    class Model3DData;
    class Bone;
    class File;
    class GraphicsApi;

    //! Manages a file in which 3D models are stored
    class M3File : public virtual ReferenceCounter
    {
    private:
        Text pfad;
        RCArray<Text>* modelName;
        Array<__int64>* modelPos;

        void saveKnochen(Bone* k, File* zDat);
        Bone* readKnochen(File* zDat) const;

    public:
        //! Constructor
        DLLEXPORT M3File();
        //! Constructor
        //! \param pfad The path to the file
        DLLEXPORT M3File(const char* pfad);
        //! Constructor
        //! \param pfad The path to the file
        DLLEXPORT M3File(Text* pfad);
        //! Destructor
        DLLEXPORT ~M3File();
        //! Sets the path to the file
        //! \param pfad Path to the file
        DLLEXPORT void setPfad(const char* pfad);
        //! Reads basic information from the file needed for its usage
        DLLEXPORT void readData();
        //! Saves 3D model data to the file
        //! \param zMdr A pointer to the data to be saved without increased
        //! reference counter \param name The name under which the data should be
        //! stored in the file \return 1 if the model was saved. 0 if an error
        //! occurred during saving
        DLLEXPORT bool saveModel(Model3DData* zMdr, Text* name);
        //! Saves 3D model data to the file
        //! \param zMdr A pointer to the data to be saved without increased
        //! reference counter \param name The name under which the data should be
        //! stored in the file \return 1 if the model was saved. 0 if an error
        //! occurred during saving
        DLLEXPORT bool saveModel(Model3DData* zMdr, const char* name);
        //! Deletes a 3D model from the file
        //! \param name The name of the model
        //! \return 1 if the model was deleted. 0 if the model was not
        //! found, or an error occurred during saving
        DLLEXPORT bool removeModel(Text* name);
        //! Deletes a 3D model from the file
        //! \param name The name of the model
        //! \return 1 if the model was deleted. 0 if the model was not
        //! found, or an error occurred during saving
        DLLEXPORT bool removeModel(const char* name);
        //! Loads a 3D model from the file
        //! \param name The name of the model to load
        //! \return The loaded data
        DLLEXPORT Model3DData* loadModel(
            Text* name, GraphicsApi* zApi, Text* uniqueName) const;
        //! Loads a 3D model from the file
        //! \param name The name of the model to load
        //! \return The loaded data
        DLLEXPORT Model3DData* loadModel(
            const char* name, GraphicsApi* zApi, const char* uniqueName) const;
        //! Checks whether a specific 3D model exists in the file
        //! \param name The name of the 3D model to search for
        //! \return 1 if the model was found. 0 otherwise
        DLLEXPORT bool hasModel(const char* name) const;
        //! Returns the number of stored models
        DLLEXPORT int getModelCount() const;
        //! Returns the name of a specific model
        //! \param i The index of the model
        //! \return A pointer to the name of the model without increased reference
        //! counter
        DLLEXPORT Text* zModelName(int i) const;
    };
} // namespace Framework