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

namespace Onward.CustomContent.Assets
{
    public class ObjectiveAssault : Objective
    {
        [Header("Boundaries for defending team")]
        public AssaultMapBoundary[] DefendingTeamBoundaries = new AssaultMapBoundary[0] { };

        [Header("Boundaries for attacking team")]
        public AssaultMapBoundary[] AttackingTeamBoundaries = new AssaultMapBoundary[0] { };

        [HideInInspector]
        [Header("Limit playable region")]
        public Transform PlayableRegionReferencePoint;

        [HideInInspector]
        [Range(10, 1000)]
        public int PlayableRegionRadius = 1000;

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

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

            if (gmAssault != null)
            {
                gmAssault.ValidateObjectiveEntries(ref DefendingTeamBoundaries);
                gmAssault.ValidateObjectiveEntries(ref AttackingTeamBoundaries);
            }

            if (AttackingTeamSpawns.Length != 2)
            {
                throw new ContentExceptionWithGameObject(gameObject, "Attack team needs two spawns.");
            }

            if (DefendingTeamSpawns.Length != 2)
            {
                throw new ContentExceptionWithGameObject(gameObject, "Defending team needs two spawns.");
            }

            if (DefendingTeamBoundaries == null || DefendingTeamBoundaries.Length <= 0)
            {
                throw new ContentExceptionWithGameObject(gameObject, "Missing boundaries for defending team.");
            }

            if (AttackingTeamBoundaries == null || AttackingTeamBoundaries.Length <= 0)
            {
                throw new ContentExceptionWithGameObject(gameObject, "Missing boundaries for attacking team.");
            }
        }

#if UNITY_EDITOR
        private void OnDrawGizmos()
        {
            if (PlayableRegionReferencePoint != null)
            {
                Gizmos.DrawWireSphere(PlayableRegionReferencePoint.position, PlayableRegionRadius);
            }

            Objective.DrawUplinkGizmo(transform);
        }
#endif
    }
}