class SaveLockRequest extends ScriptableSystemRequest
{
	var operation : EItemOperationType;
	var reason : CName;
}

class SaveLocksManager extends ScriptableSystem
{
	private var m_saveLocks : array< CName >;

	private export override function IsSavingLocked() : Bool
	{
		return m_saveLocks.Size() > 0;
	}

	protected export function OnSaveLockRequest( request : SaveLockRequest )
	{
		if( request.operation == EItemOperationType.ADD )
		{
			AddSaveLock( request.reason );
		}
		else if( request.operation == EItemOperationType.REMOVE )
		{
			RemoveSaveLock( request.reason );
		}
	}

	private function AddSaveLock( reason : CName )
	{
		if( IsNameValid( reason ) && !( m_saveLocks.Contains( reason ) ) )
		{
			m_saveLocks.PushBack( reason );
		}
	}

	private function RemoveSaveLock( reason : CName )
	{
		m_saveLocks.Remove( reason );
	}

	public static function RequestSaveLockAdd( game : GameInstance, reason : CName )
	{
		var request : SaveLockRequest;
		if( GameInstance.IsValid( game ) )
		{
			request = new SaveLockRequest;
			request.operation = EItemOperationType.ADD;
			request.reason = reason;
			GameInstance.QueueScriptableSystemRequest( game, 'SaveLocksManager', request );
		}
	}

	public static function RequestSaveLockRemove( game : GameInstance, reason : CName )
	{
		var request : SaveLockRequest;
		if( GameInstance.IsValid( game ) )
		{
			request = new SaveLockRequest;
			request.operation = EItemOperationType.REMOVE;
			request.reason = reason;
			GameInstance.QueueScriptableSystemRequest( game, 'SaveLocksManager', request );
		}
	}

}

