public class LevelSegment : MonoBehaviour
{
    [SerializeField] private MeshRenderer meshRenderer;
    [SerializeField] private List<Vector2> transitionDirections = new List<Vector2>();

    public Vector3 GetExtents {get{return meshRenderer.bounds.extents;}}
    public Vector3 CurrentNextPosition = new Vector3();
    
    public bool HasEntryDirection(Vector2 entryDirection)
    {
        return transitionDirections.Contains(entryDirection);
    }

    public bool IsValid(Vector3 startPos, Vector2 entryDirection, List<Vector3> currentPositions)
    {
        bool _hasEntry = HasEntryDirection(entryDirection);
        CurrentNextPosition = GetNextPosition(startPos, entryDirection);
        bool _hasExit = !currentPositions.Contains(CurrentNextPosition);
        return _hasEntry && _hasExit;
    }
    
    public Vector3 GetNextPosition(Vector3 startPos, Vector2 entryDirection)
    {
        Vector2 v_possible = GetPossibleDirections(entryDirection);
        Vector3 returnPos = startPos + new Vector3(v_possible.x * GetExtents.x * 2f, 0f, v_possible.y * GetExtents.z * 2f);
        returnPos = Vector3Int.RoundToInt(returnPos);
        Debug.DrawRay(returnPos, Vector3.up * 5f, Color.green, 5f);
        return returnPos;
    }
    
    public Vector2 GetPossibleDirections(Vector2 entryDirection)
    {
        List<Vector2> availableDirections = new List<Vector2>();
        for (int i = 0; i < transitionDirections.Count; i++)
        {
            if(transitionDirections[i] != entryDirection) availableDirections.Add(transitionDirections[i]);
        }

        return availableDirections[Random.Range(0,availableDirections.Count)];
    } 
    
    public Vector2 GetPossibleDirections()
    {
        Vector2 v = transitionDirections[Random.Range(0,transitionDirections.Count)];
        return v;
    }
}