#ifndef _BACKENDDEF_
#define _BACKENDDEF_

#include "sys/sys"
#include "error/error"
#include "profiler/profiler"
#include "backendcheck/backendcheck"
#include "ThreadsAndMutexes/mutex/mutex"

using namespace std;

class BackendDef {
public:
    BackendDef():
    srv(""), prt(-1), max(0), host_match(""), url_match(""),
	wt(1), backend_check() {
	hostmatch("");
	urlmatch("");
    }
    BackendDef(string s, string p, string m = "", string w = "1");

    void server(string s) 			{ srv = s; }
    string const &server() const		{ return (srv); }
    
    void port (int p) 				{ prt = p; }
    int port() const 				{ return (prt); }
    
    unsigned maxconn() const 			{ return (max); }
    void maxconn (unsigned m)			{ max = m; }

    unsigned weight() const			{ return wt; }
    void weight (unsigned w);
    unsigned adjustedweight() const		{ return min_wt +
	                                          max_wt - wt; }
    
    void hostmatch(string const &s);
    string const &hostmatch() const		{ return (host_match); }
    regex_t const &hostregex() const		{ return (host_regex); }

    void urlmatch(string const &u);
    string const &urlmatch() const		{ return (url_match); }
    regex_t const &urlregex() const		{ return (url_regex); }

    BackendCheck const &backendcheck()		{ return backend_check; }
    void backendcheck(BackendCheck const &b) 	{ backend_check = b; }	
    
private:
    string srv;    
    int prt;
    unsigned max;
    string host_match;
    regex_t host_regex;
    string url_match;
    regex_t url_regex;
    unsigned wt;
    static unsigned min_wt, max_wt;
    static bool minmax_wt_set;
    BackendCheck backend_check;
};

#endif
