#pragma once

#include "Common.h"
#include "InformationManager.h"
#include "StrategyManager.h"
#include "MapTools.h"

namespace MyBot
{
	class Strategy_ScoutTaskManager
	{
		Strategy_ScoutTaskManager();

		/// 디버깅용 플래그 : 어느 코드가 에러를 일으키는지 알기위한 플래그
		bool isToFindError;


		UnitData * enemyUnitData;
		UnitData * myUnitData;
		BWTA::BaseLocation * enemyMainBaseLocation;
		BWTA::BaseLocation * myMainBaseLocation;
		BWTA::BaseLocation * enemyFirstExpansionBaseLocation;
		BWTA::Chokepoint * enemyFirstChokepoint;

		int								currentScoutWorkerStatus;
		int								currentScoutOverlordStatus;
		int								currentScoutZerglingStatus;

		BWAPI::Unit						currentScoutWorker;
		BWAPI::Unit						currentScoutOverlord;
		BWAPI::Unit						currentScoutZergling;

		BWTA::BaseLocation *			currentScoutWorkerTargetBaseLocation;
		BWTA::BaseLocation *			currentScoutOverlordTargetBaseLocation;
		BWTA::BaseLocation *			currentScoutZerglingTargetBaseLocation;
		int								currentScoutTargetDistance;

		int                             currentScoutFreeToVertexIndex;
		std::vector<BWAPI::Position>    enemyBaseRegionVertices;
		BWAPI::Position					currentScoutTargetPosition;

		void							assignScoutIfNeeded();






		/// 정찰 부대를 적 BaseLocation 을 찾기위해 이동시킵니다
		void                            moveScoutSquadToFindEnemyBaseLocation();
		
		/// 정찰 부대를 적 BaseLocation 을 정찰하기 위해 이동시킵니다
		void							moveScoutSquadToScoutEnemyBaseLocation();

		std::map<BWAPI::Unit, BWAPI::Position> scoutUnitAndPositionMap;

		void							moveScoutSquadToScoutEnemyFirstExpansion();
		void							moveScoutSquadToScoutEnemyOtherExpansion(StrategicTask task);
		void							moveScoutSquadToScoutEnemyOuterChokePoint();
		void							moveScoutSquadToScoutMyOuterChokePoint();
		void							moveScoutSquadToScoutOurFirstExpansion();

		/// 정찰 부대를 Empty BaseLocations 에 이동시킵니다
		void                            moveScoutSquadToEmptyBaseLocations();

		/// 저글링 정찰 부대를 BaseLocation 위치에 버로우시킵니다
		void							moveScoutSquadToBurrowOnBaseLocation();
		/// 저글링 정찰 부대를 특정 위치에 버로우시킵니다
		void							moveMultiObstructSquadToScoutBaseLocations();

		/// 정찰 부대를 지도 전체를 훑으며 이동시킵니다
		void                            moveScoutSquadForEntireMap();


		/// 럴커를 적군 확장 길목에 매복시킵니다
		void							obstructEnemyExpansionWithLurker();


		void							clearFinishedScoutUnit();

		void                            calculateEnemyRegionVertices();
		BWAPI::Position                 getScoutFleePositionFromEnemyRegionVertices(BWAPI::Unit unit);
		int                             getClosestVertexIndex(BWAPI::Unit unit);

		/// 헬퍼함수 : 정찰 대상 BaseLocation 을 리턴합니다
		BWTA::BaseLocation*				getNextEmptyBaseLocaionToScout(BWAPI::UnitType unitType = BWAPI::UnitTypes::Zerg_Zergling);
	public:
		/// static singleton 객체를 리턴합니다
		static Strategy_ScoutTaskManager & Instance();

		void update();

		void drawStatus();
	};
}