#ifndef IMAGELOADER_H
#define IMAGELOADER_H

#include <string>
#include <memory>
#include "../buffer/imagebuffer.h"

/**
 * @brief The ImageLoader class provides static methods for loading and saving images.
 */
class ImageLoader
{
    public:
        /**
         * @brief Load an image from a file
         * @param filename The filename to load
         * @return A shared pointer to the loaded image buffer
         * @throws std::runtime_error if the file cannot be loaded
         */
        static std::shared_ptr<ImageBuffer8bit> loadImage(const std::string &filename);

        /**
         * @brief Save an image to a file
         * @param filename The filename to save to
         * @param image The image buffer to save
         * @throws std::runtime_error if the file cannot be saved
         */
        static void saveImage(const std::string &filename, const std::shared_ptr<ImageBuffer8bit> &image);

    private:
        /**
         * @brief Load a JPEG image
         * @param filename The filename to load
         * @return A shared pointer to the loaded image buffer
         */
        static std::shared_ptr<ImageBuffer8bit> loadJpeg(const std::string &filename);

        /**
         * @brief Load a FITS image
         * @param filename The filename to load
         * @return A shared pointer to the loaded image buffer
         */
        static std::shared_ptr<ImageBuffer8bit> loadFits(const std::string &filename);

        /**
         * @brief Save a JPEG image
         * @param filename The filename to save to
         * @param image The image buffer to save
         */
        static void saveJpeg(const std::string &filename, const std::shared_ptr<ImageBuffer8bit> &image);

        /**
         * @brief Save a FITS image
         * @param filename The filename to save to
         * @param image The image buffer to save
         */
        static void saveFits(const std::string &filename, const std::shared_ptr<ImageBuffer8bit> &image);

        /**
         * @brief Get the file extension from a filename
         * @param filename The filename
         * @return The file extension in lowercase
         */
        static std::string getFileExtension(const std::string &filename);
};

#endif // IMAGELOADER_H
