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

using System.Collections.Generic;
using GameCreator.Core;
using GameCreator.Variables;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;

#endif

namespace BansheeGz.BGDatabase
{
    /// <summary>
    /// get row's index by ID or name 
    /// </summary>
    public class BGGCGetRowIndex : BGGCRowA
    {
        [VariableFilter(Variable.DataType.Number)]
        public VariableProperty saveToVar;

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

            var entity = GetEntity(target);
            if (entity == null)
            {
                Debug.Log("WARNING! BGDatabase: row is null!");
                return true;
            }

            saveToVar.Set(entity.Index, target);
            return true;
        }
        // +--------------------------------------------------------------------------------------+
        // | EDITOR                                                                               |
        // +--------------------------------------------------------------------------------------+
#if UNITY_EDITOR
        public static new string NAME = "BansheeGz/Get row index";
        protected override string Title => "BGDatabase: Get row index";

        public override void EditorGui()
        {
            base.EditorGui();
            EditorGUILayout.PropertyField(Prop(nameof(saveToVar)));
        }
#endif
    }
}