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

using System;
using System.Threading.Tasks;
using GameCreator.Runtime.Common;
using GameCreator.Runtime.Variables;
using UnityEngine;

namespace BansheeGz.BGDatabase
{
    [Title("BGDatabase: add row")]
    [Category("BansheeGz/add row")]
    [Serializable]
    public class BGGCAddRow : BGGCTableA
    {
        public override string Title => "BGDatabase: Add a row";

        [SerializeField] private PropertySetNumber row = SetNumberGlobalName.Create;

        protected override Task Run(Args args)
        {
            var meta = Meta;
            if (meta == null) Debug.Log("WARNING! BGDatabase: can not access a target meta!");
            else
            {
                var newIndex = meta.NewEntity().Index;
                row.Set(newIndex, args);
            }

            return DefaultResult;
        }

        /*
        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";

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