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

namespace Onward.CustomContent.Assets
{
    public class AssaultMapBoundary : Entity
    {
        public override void Validate()
        {
            base.Validate();

            GM_Assault gmAssault = GameObject.FindObjectOfType<GM_Assault>();

            List<AssaultMapBoundary> boundaries = new List<AssaultMapBoundary>();

            foreach (ObjectiveAssault obj in gmAssault.Objectives)
            {
                if (obj == null)
                    throw new CustomContent.ContentExceptionWithGameObject(gmAssault.gameObject, "Assault gamemode contains invalid objective(s).");

                boundaries.AddRange(obj.AttackingTeamBoundaries);
                boundaries.AddRange(obj.DefendingTeamBoundaries);
            }

            if (!boundaries.Contains(this))
            {
                throw new CustomContent.ContentExceptionWithGameObject(gameObject, $"Loose AssaultMapBoundary not allowed. Please assign it to an {nameof(ObjectiveAssault)} or remove it.");
            }
        }

#if UNITY_EDITOR
        private void OnDrawGizmos()
        {
            Gizmos.color = new Color(1f, 0, 0, 0.25f);

            Gizmos.DrawCube(transform.position, transform.lossyScale);
        }
#endif
    }
}