////////////////////////////////////////////////////////////////////////////////
//    Scorched3D (c) 2000-2011, 2025, 2026
//
//    This file is part of Scorched3D.
//
//    Scorched3D is free software; you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation; either version 2 of the License, or
//    (at your option) any later version.
//
//    Scorched3D is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License along
//    with this program; if not, write to the Free Software Foundation, Inc.,
//    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
////////////////////////////////////////////////////////////////////////////////

#ifndef __INCLUDE_ServerDestination_hpp_INCLUDE__
#define __INCLUDE_ServerDestination_hpp_INCLUDE__

#include <list>
#include <common/RollingAverage.hpp>
#include <net/NetBuffer.hpp>

struct ModIdentifierEntry;

class ServerDestinationMod
{
public:
	ServerDestinationMod();
	virtual ~ServerDestinationMod();

	// clang-format off
	// uncrustify off
	void setReadyToReceive( bool r ) { readyToReceive_ = r; }
	bool getReadyToReceive()         { return readyToReceive_; }

	void setInit( bool i ) { init_ = i; }
	bool getInit()         { return init_; }

	void setTotalLeft( unsigned int size ) { totalLeft_ = size; };
	unsigned int getTotalLeft()            { return totalLeft_; }
	// uncrustify on
	// clang-format on

	void                addFile( ModIdentifierEntry& entry );
	void                rmFile( const char* file );
	ModIdentifierEntry* getNextFile();

	NetBuffer& getSendBuffer() { return sendBuffer_; }

protected:
	bool                             readyToReceive_;
	bool                             init_;
	unsigned int                     totalLeft_;
	NetBuffer                        sendBuffer_;
	std::string                      lastFile_;
	std::list< ModIdentifierEntry >* files_;  // Pointer so we don't include ModFiles.hpp
};

class ServerDestination
{
public:
	enum State
	{
		sDownloadingMod,
		sInitializingMod,
		sLoadingLevel,
		sFinished
	};

	ServerDestination( unsigned int destinationId, unsigned int ipAddress );
	virtual ~ServerDestination();

	// clang-format off
	// uncrustify off
	void  setState( State s );
	State getState() { return state_; }

	unsigned int getDestinationId() { return destinationId_; }
	unsigned int getIpAddress()     { return ipAddress_; }

	void setAdmin( bool admin ) { admin_ = admin; }
	bool getAdmin()             { return admin_; }

	int  getAdminTries()                 { return adminTries_; }
	void setAdminTries( int adminTries ) { adminTries_ = adminTries; }

	unsigned int getLevelNumber()                  { return levelNumber_; }
	void         setLevelNumber( unsigned int ln ) { levelNumber_ = ln; }

	ServerDestinationMod& getMod()  { return mod_; }
	RollingAverage&       getPing() { return ping_; }

	fixed getLastSentPingTime()          { return lastSentPingTime_; }
	void  setLastSentPingTime( fixed t ) { lastSentPingTime_ = t; }
	// uncrustify on
	// clang-format on

protected:
	ServerDestinationMod mod_;
	State                state_;
	unsigned int         destinationId_;
	unsigned int         ipAddress_;
	unsigned int         levelNumber_;
	bool                 admin_;
	int                  adminTries_;
	RollingAverage       ping_;
	fixed                lastSentPingTime_;
};

#endif  // __INCLUDE_ServerDestination_hpp_INCLUDE__
