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

using HamJam.Character;

public class AttackDataManagerScript : MonoBehaviour {

    [SerializeField]
    private List<AttackData> _attackDataList;

    private Dictionary<AttackTypes, AttackData> _attackData;

    void Awake() {
        this._attackData = new Dictionary<AttackTypes, AttackData>();
        foreach (var data in this._attackDataList) {
            this._attackData[data.Type] = data;
        }
    }

    public float GetAttackRange(AttackTypes attackType) {
        if (!this._attackData.ContainsKey(attackType)) {
            throw new ArgumentException("The provided type (namely '" + attackType + "') is not in the " +
                                        "dictionary. Did you forget to add it to the AttackDataManager?");
        }
        return this._attackData[attackType].Range;
    }

    public float GetAttackDamage(AttackTypes attackType) {
        if (!this._attackData.ContainsKey(attackType)) {
            throw new ArgumentException("The provided type (namely '" + attackType + "') is not in the " +
                                        "dictionary. Did you forget to add it to the AttackDataManager?");
        }
        return this._attackData[attackType].Damage;
    }

    public GameObject GetAttackPrefab(AttackTypes attackType) {
        if (!this._attackData.ContainsKey(attackType)) {
            throw new ArgumentException("The provided type (namely '" + attackType + "') is not in the " +
                                        "dictionary. Did you forget to add it to the AttackDataManager?");
        }
        return this._attackData[attackType].Prefab;
    }

    public float GetAttackTimeout(AttackTypes attackType) {
        if (!this._attackData.ContainsKey(attackType)) {
            throw new ArgumentException("The provided type (namely '" + attackType + "') is not in the " +
                                        "dictionary. Did you forget to add it to the AttackDataManager?");
        }
        return this._attackData[attackType].Timeout;
    }
}

namespace HamJam {
    namespace Character {
        [Serializable]
        public struct AttackData {
            [SerializeField]
            private AttackTypes _attackType;
            [SerializeField]
            private float _range;
            [SerializeField]
            private int _damage;
            [SerializeField]
            private GameObject _prefab;
            [SerializeField]
            private float _attackTimeout;

            public AttackTypes Type {
                get {
                    return this._attackType;
                }
            }
            public float Range {
                get {
                    return this._range;
                }
            }
            public int Damage {
                get {
                    return this._damage;
                }
            }
            public GameObject Prefab {
                get {
                    return this._prefab;
                }
            }
            public float Timeout {
                get {
                    return this._attackTimeout;
                }
            }
        }

    }
}
