/*
<copyright file="BGGCAddRow.cs" company="BansheeGz">
    Copyright (c) 2018-2021 All Rights Reserved
</copyright>
*/


using GameCreator.Core;
using GameCreator.Variables;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif

namespace BansheeGz.BGDatabase
{
    public class BGGCAddRow : BGGCTableA
    {
        [VariableFilter(Variable.DataType.Number)]
        public VariableProperty rowIndex;

        public override bool InstantExecute(GameObject target, IAction[] actions, int index)
        {
            var meta = Meta;
            if (meta == null)
            {
                Debug.Log("WARNING! BGDatabase: can not access a target meta!");
                return true;
            }

            var newIndex = meta.NewEntity().Index;
            if (rowIndex != null) rowIndex.Set(newIndex, target);

            return true;
        }
        
        // +--------------------------------------------------------------------------------------+
        // | EDITOR                                                                               |
        // +--------------------------------------------------------------------------------------+
#if UNITY_EDITOR
        public static new string NAME = "BansheeGz/Add a row";
        protected override string Title => "BGDatabase: Add a row";

        public override void EditorGui()
        {
            base.EditorGui();
            EditorGUILayout.PropertyField(Prop(nameof(rowIndex)), new GUIContent("Added entity index"));
        }
#endif
    }
}