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

using System;
using GameCreator.Runtime.Common;
using UnityEngine;

namespace BansheeGz.BGDatabase
{
    /// <summary>
    /// reference to a table 
    /// </summary>
    [BGPlugin(Version = "1.3")]
    [Serializable]
    public abstract class BGGCTableA : BGGCAction
    {
        [SerializeField] private string tableId;

        private BGMetaEntity meta;

        public void ResetMeta() => meta = null;

        public BGMetaEntity Meta
        {
            get
            {
                if (meta != null && !meta.IsDeleted) return meta;
                meta = null;
            
                if (string.IsNullOrEmpty(tableId)) return null;
                if (!BGId.TryParse(tableId, out var metaId)) return null;

                meta = BGRepo.I.GetMeta(metaId);
                return meta;
            }
        }
    }
}