#ifndef RESOURCE_H
#define RESOURCE_H
#include <string>
#include "mime_types.hpp"
#include "reply.hpp"
#include "request.hpp"


namespace http::resource {
    /**
     * Абстрактный ресурс
     */
    class BasicResource {
    public:
        std::string path;

        virtual void handle(const server::Request &req, server::reply &rep) = 0;

        virtual ~BasicResource() = default;
    };

    /**
     * Класс ресурса статического файла
     */
    class StaticFileResource final : public BasicResource {
    private:
        server::mime_types::Mime type;
#ifdef USE_DEBUG
        std::string filePath;
#else
        std::vector<char> content;
#endif

    public:
        StaticFileResource(const std::string& path, const std::string& filePath, server::mime_types::Mime type);

        void handle(const server::Request &req, server::reply &rep) override;

        ~StaticFileResource() override;
    };

    using respGenerator = std::function<void(const server::Request &req, server::reply &rep)>;

    /**
     * Класс ресурса для POST-запросов
     */
    class GenericResource final : public BasicResource {
    private:
        respGenerator generator_;

    public:
        GenericResource(const std::string& path, const respGenerator& generator);

        void handle(const server::Request &req, server::reply &rep) override;

        ~GenericResource() override;
    };
}

#endif //RESOURCE_H
