#ifndef MANAGEPAGE_H
#define MANAGEPAGE_H

#include "accountManager.h"
#include "curl/curl.h"
#include "parameterManager.h" // for isNumber

#include <sstream>
#include <unistd.h> // sleep
#include <algorithm>
#include <ctime> // std::time, localtime ...


struct Reply {
    Reply() {}
    Reply(std::string value_both) : html(value_both), url(value_both) {}
    Reply(std::string html, std::string url) : html(html), url(url) {}

    std::string html, url;
};


class PageManager
{
public:
    PageManager(std::string sock5ProxyOnlyAddress = "127.0.0.1:9150", std::string cookieFilePath = "/tmp/S_New4_cookies");
    ~PageManager();

    void setProxy(std::string ip, int port);
    void setCookieFilePath(std::string path);
    void setDebugMode(bool status);

    Reply getServerRequest(std::string Url, bool useCookies = false, std::string data = "", bool generateCookieFile = false);
    int downLoadToFile(std::string filePath, std::string url);

    int login(Account account);
    std::string getUrlAfterRedirect(std::string Url);
    std::string checkName(std::string Name);
    std::string getLinks(std::string HTML);
    std::string chooseHosterLink(std::string HosterList, std::string Hoster_with_Highst_Priority_at_First, std::string languages_with_highst_priority_at_first);

    std::string replace(std::string str, std::string substr1, std::string substr2);
    int counterContains(std::string text, std::string substring_with_prozent_i_for_number, int starte_mit_dieser_Zahl = 1);
    std::string grep(std::string text, std::string substring, bool IgnoreCaseSensetifity = false);
    std::string upper_string(const std::string& str);
    size_t getDate();
    std::string getExePath();

    int compareVersions(std::string Version1, std::string Version2);

    int writeToFile(std::string path, std::string text);

    const std::string UrlPraefix = "https://s.to/serie/stream/";
    std::string sock5Proxy;
private:
    std::string cookieFilePath;
    bool debugMode = false;
};

#endif // MANAGEPAGE_H
