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

using System;
using NodeCanvas.Framework;
using ParadoxNotion.Design;

namespace BansheeGz.BGDatabase
{
    [BGPlugin(Version = "1.0")]
    public abstract class BGNCTableA : ActionTask
    {
        [RequiredField]
        public BBParameter<string> tableName;

        private BGMetaEntity meta;

        public BGMetaEntity Meta
        {
            get
            {
                var realTableName = tableName.value;
                if (meta != null && !meta.IsDeleted && string.Equals(meta.Name, realTableName, StringComparison.Ordinal)) return meta;
                meta = null;
                if (string.IsNullOrEmpty(realTableName)) throw new Exception($"Can not retrieve a meta, cause specified meta name is empty!");
                meta = BGRepo.I.GetMeta(realTableName);
                if (meta == null) throw new Exception($"Can not retrieve a meta, cause there is no meta with specified name={realTableName}!");
                return meta;
            }
        }
    }
}