﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Onward.CustomContent.Assets
{
    public class GM_FreeRoam : GM_Base
    {
        [Header("Defending Team")]
        public SpawnSystem[] DefendingTeamSpawns;

        [Header("Attacking Team")]
        public SpawnSystem[] AttackingTeamSpawns;

        public GM_FreeRoam()
           : base(GM_Base.EGameModeType.None)
        {
        }

        void Start()
        {
            Util.EnforceSingleInstance<GM_FreeRoam>();
        }

        public override void Validate()
        {
            base.Validate();

            Objective.ValidateSpawnSystemEntries(ref AttackingTeamSpawns, gameObject);
            Objective.ValidateSpawnSystemEntries(ref DefendingTeamSpawns, gameObject);

            if (DefendingTeamSpawns.Length <= 0)
                throw new ContentExceptionWithGameObject(gameObject, "No spawns for defending team.");

            if (AttackingTeamSpawns.Length <= 0)
                throw new ContentExceptionWithGameObject(gameObject, "No spawns for attacking team.");
        }

#if UNITY_EDITOR
        private void OnDrawGizmosSelected()
        {
            if (DefendingTeamSpawns != null)
            {
                foreach (var spawnSys in DefendingTeamSpawns)
                {
                    spawnSys.DrawLinesTo(transform.position);
                }
            }

            if (AttackingTeamSpawns != null)
            {
                foreach (var spawnSys in AttackingTeamSpawns)
                {
                    spawnSys.DrawLinesTo(transform.position);
                }
            }
        }
#endif
    }
}