using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UniRx;
using Unity.Linq;
public class MapChunk : MapElement
{
    public int ID;

    public Road Road;

    public GameObject PeopleParent;
    public GameObject SpawnPointsParent;
    public GameObject[] spawnPoints;
    public event Action<MapChunk> MapEnded;
    void Start()
    {

        Road = gameObject.Child("Road").GetComponent<Road>();
        SpawnPointsParent = Road.gameObject.Child("SpawnPointsParent");
        PeopleParent = Road.gameObject.Child("PeopleParent");
        spawnPoints = SpawnPointsParent.Children().ToArray();

        // MapPooled.Subscribe(x =>
        // {
        //     Debug.Log("spawn");
        //     
        // }).AddTo(this);
    }
    public void MapSpawned()
    {
        var spawner = GetComponentInParent<Spawner>();
        spawner.Spawn(this);
    }
    public void MapEndedRaise()
    {
        MapEnded?.Invoke(this);

    }
    // System.Random random = new System.Random(543453);
    // void ConfigureSpawn()
    // {
    //     var point = random.Next(0, spawnPoints.Length);
    //     spawner.externalPosition = spawnPoints[point].transform.position;
    //
    // }
    //
    // private void Spawner_Spawned(GameObject spawned)
    // {
    //     spawned.transform.parent = Road.transform;
    //     ConfigureSpawn();
    // }


}
