using System;
using System.Collections.Generic;

namespace XGame.Framework.Asset
{
    public class CSharpAssetReferencesManifest : IAssetReferencesManifest, IDisposable
    {
        /// <summary>
        /// key:assetPath
        /// value:references
        /// </summary>
        private Dictionary<string, string[]> _referencesMap;

        public CSharpAssetReferencesManifest(AssetReferenceInfosSo manifest)
        {
            _referencesMap = new Dictionary<string, string[]>();
            Init(manifest);
        }
        private void Init(AssetReferenceInfosSo manifest)
        {
            if (manifest == null || manifest.references == null)
                return;
            foreach(var reference in manifest.references)
            {
                _referencesMap.Add(reference.assetName, reference.references);
            }
        }
        public string[] GetReferencesByAssetName(string assetName)
        {
            _referencesMap.TryGetValue(assetName, out var result);
            return result;
        }

        void IDisposable.Dispose()
        {
            _referencesMap.Clear();
        }
    }
}
