using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Robust.Shared.GameObjects;
using Robust.Shared.Maths;
using Robust.Shared.Timing;
namespace Robust.Shared.Map
{
///
/// This manages all of the grids in the world.
///
public interface IMapManager : IPauseManager
{
///
/// A faster version of
///
GridEnumerator GetAllGridsEnumerator();
IEnumerable GetAllGrids();
///
/// Should the OnTileChanged event be suppressed? This is useful for initially loading the map
/// so that you don't spam an event for each of the million station tiles.
///
bool SuppressOnTileChanged { get; set; }
///
/// Get the set of grids that have moved on this map in this tick.
///
HashSet GetMovedGrids(MapId mapId);
///
/// Clear the set of grids that have moved on this map in this tick.
///
void ClearMovedGrids(MapId mapId);
///
/// Starts up the map system.
///
void Initialize();
void Shutdown();
void Startup();
void Restart();
///
/// Creates a new map.
///
///
/// If provided, the new map will use this ID. If not provided, a new ID will be selected automatically.
///
/// The new map.
///
/// Throw if an explicit ID for the map or default grid is passed and a map or grid with the specified ID already exists, respectively.
///
MapId CreateMap(MapId? mapId = null);
///
/// Check whether a map with specified ID exists.
///
/// The map ID to check existence of.
/// True if the map exists, false otherwise.
bool MapExists(MapId mapId);
///
/// Creates a new entity, then sets it as the map entity.
///
/// Newly created entity.
EntityUid CreateNewMapEntity(MapId mapId);
///
/// Sets the MapEntity(root node) for a given map. If an entity is already set, it will be deleted
/// before the new one is set.
///
void SetMapEntity(MapId mapId, EntityUid newMapEntityId);
///
/// Returns the map entity ID for a given map.
///
EntityUid GetMapEntityId(MapId mapId);
///
/// Replaces GetMapEntity()'s throw-on-failure semantics.
///
EntityUid GetMapEntityIdOrThrow(MapId mapId);
IEnumerable GetAllMapIds();
void DeleteMap(MapId mapId);
IMapGrid CreateGrid(MapId currentMapId, GridId? gridId = null, ushort chunkSize = 16);
IMapGrid GetGrid(GridId gridId);
bool TryGetGrid(GridId gridId, [NotNullWhen(true)] out IMapGrid? grid);
bool GridExists(GridId gridId);
IEnumerable GetAllMapGrids(MapId mapId);
///
/// Attempts to find the map grid under the map location.
///
///
/// This method will never return the map's default grid.
///
/// Map to search.
/// Location on the map to check for a grid.
/// Grid that was found, if any.
/// Returns true when a grid was found under the location.
bool TryFindGridAt(MapId mapId, Vector2 worldPos, [NotNullWhen(true)] out IMapGrid? grid);
///
/// Attempts to find the map grid under the map location.
///
///
/// This method will never return the map's default grid.
///
/// Location on the map to check for a grid.
/// Grid that was found, if any.
/// Returns true when a grid was found under the location.
bool TryFindGridAt(MapCoordinates mapCoordinates, [NotNullWhen(true)] out IMapGrid? grid);
void FindGridsIntersectingEnumerator(MapId mapId, Box2 worldAabb, out FindGridsEnumerator enumerator, bool approx = false);
///
/// Returns the grids intersecting this AABB.
///
/// The relevant MapID
/// The AABB to intersect
/// Set to false if you wish to accurately get the grid bounds per-tile.
///
IEnumerable FindGridsIntersecting(MapId mapId, Box2 worldAabb, bool approx = false);
///
/// Returns the grids intersecting this AABB.
///
/// The relevant MapID
/// The AABB to intersect
/// Set to false if you wish to accurately get the grid bounds per-tile.
IEnumerable FindGridsIntersecting(MapId mapId, Box2Rotated worldArea, bool approx = false);
void DeleteGrid(GridId gridId);
///
/// A tile is being modified.
///
[Obsolete("Subscribe to TileChangedEvent on the event bus.")]
event EventHandler TileChanged;
[Obsolete("Subscribe to GridStartupEvent on the event bus.")]
event GridEventHandler OnGridCreated;
[Obsolete("Subscribe to GridRemovalEvent on the event bus.")]
event GridEventHandler OnGridRemoved;
///
/// A Grid was modified.
///
[Obsolete("Subscribe to GridModifiedEvent on the event bus.")]
event EventHandler GridChanged;
///
/// A new map has been created.
///
[Obsolete("Subscribe to MapChangedEvent on the event bus, and check if Created is true.")]
event EventHandler MapCreated;
///
/// An existing map has been destroyed.
///
[Obsolete("Subscribe to MapChangedEvent on the event bus, and check if Destroyed is true.")]
event EventHandler MapDestroyed;
bool HasMapEntity(MapId mapId);
bool IsGrid(EntityUid uid);
bool IsMap(EntityUid uid);
[Obsolete("Whatever this is used for, it is a terrible idea. Create a new map and get it's MapId.")]
MapId NextMapId();
EntityUid GetGridEuid(GridId id);
IMapGridComponent GetGridComp(GridId id);
IMapGridComponent GetGridComp(EntityUid euid);
bool TryGetGrid(EntityUid euid, [NotNullWhen(true)] out IMapGrid? grid);
bool GridExists(EntityUid euid);
}
}