using Sirenix.OdinInspector;
using UnityEngine;
using VOID.Generic.Dict;
using VOID.ScriptableObjects.Abilities;

namespace VOID.Generic.Objects.Weapon
{
    [System.Serializable]
    public class WeaponObjectData : ObjectComponent<WeaponObject>
    {
        #region Initialize

        protected override void SelfInitialize()
        {
            if (handPoint)
            {
                // Calculate and cache - unit will hold weapon by this position and rotation - Transform defined in prefab
                handRotationOffset = Quaternion.Inverse(handPoint.transform.localRotation);
                handPositionOffset = handRotationOffset * handPoint.transform.localPosition * - 1;
            }

            if (secondHandPoint)
            {
                // Calculate and cache - mainly for two-handed weapons - it IK point for second hand
                secondHandPositionOffset = handRotationOffset * secondHandPoint.transform.localPosition * - 1;
                secondHandPositionOffset = handPositionOffset - secondHandPositionOffset;
            }
        }

        #endregion

        [Title("Visuals")]
        [Required, ChildGameObjectsOnly] public GameObject model;
        
        [Title("IK targets")]
        [Required, ChildGameObjectsOnly] public GameObject handPoint;
        public Quaternion handRotationOffset { get; private set; }
        public Vector3 handPositionOffset { get; private set; }
        [ChildGameObjectsOnly, ShowIf(nameof(weaponCarryType), WeaponCarryType.TwoHand)] public GameObject secondHandPoint;
        public Vector3 secondHandPositionOffset { get; private set; }
        
        [Title("Weapon attributes")]
        public WeaponType weaponType;
        public WeaponCarryType weaponCarryType;
        public DamageType damageType;
        [MinValue(0)] public int damageMin;
        [MinValue(nameof(damageMin))] public int damageMax;
        [MinValue(0)] public float criticalDamageChange;
        [MinValue(1)] public float criticalDamageMultiplier;

        [Title("Default Attack Ability")]
        [Required] public BasicAttackAbility attackAbility;
    }
}
