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


using System;
using Bolt;
using Ludiq;

namespace BansheeGz.BGDatabase
{
    [UnitCategory("BansheeGz")]
    public class BGDatabaseGetEntityIndex : Unit
    {
        [DoNotSerialize] public ValueInput entity;
        [DoNotSerialize] public ValueOutput index;

        protected override void Definition()
        {
            entity = ValueInput<string>("Entity", "");
            index = ValueOutput<int>("count", GetCount);
        }

        private int GetCount(Flow flow)
        {
            var row = flow.GetValue<BGEntity>(entity);
            if (row == null) throw new Exception("Entity is null!");
            return row.Index;
        }
    }
}