//
// Created by m on 12/5/21.
//

#ifndef RLA_IIPP_SDLFONTMANAGER_HPP
#define RLA_IIPP_SDLFONTMANAGER_HPP


#include <string>
#include <utility>
#include <SDL_ttf.h>
#include "../../resources/resourcemanager.hpp"

struct SdlFontArgs {
    int size;
    std::string font_path;

    SdlFontArgs(int size, std::string fontPath) : size(size), font_path(std::move(fontPath)) {}
};

class SdlFontManager : public ResourceManager<std::shared_ptr<TTF_Font>, std::string, SdlFontArgs> {
    std::string get_key(SdlFontArgs args) override;

    std::shared_ptr<TTF_Font> load_resource(SdlFontArgs args) override;
};




class MissingFontException : public std::exception {
private:
    std::string msg;

public:
    [[nodiscard]] const char *what() const _GLIBCXX_TXN_SAFE_DYN _GLIBCXX_NOTHROW override {
        return msg.c_str();
    }

    explicit MissingFontException(const std::string& missing_font, std::string reason) {
        msg = fmt::format("Unable to load font [{}] because: {}", missing_font, reason);
    }
};


#endif //RLA_IIPP_SDLFONTMANAGER_HPP
