using System.IO;
using UnityEngine;

namespace RothenburgAR.PointOfInterest
{
    class PoiModelLoader
    {
        public GameObject LoadModel(PoiModelDescription description)
        {
            if (!File.Exists(description.ModelPath))
            {
                throw new FileNotFoundException(description.ModelPath + " does not exist;");
            }

            var asset = AssetBundle.LoadFromFile(description.ModelPath);
            if (!asset)
            {
                Debug.Log("Failed to load AssetBundle!");
                return null;
            }
            var prefab = asset.LoadAsset(description.ModelPrefabName) as GameObject;

            prefab.transform.localScale = description.Scale;
            prefab.transform.localPosition = description.Position;
            prefab.transform.Rotate(description.Rotation);
            return prefab;
        }
    }
}