using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public class DanMachiModelBuilder : ModelBuilder
{
    public static DanMachiModelBuilder Instance => GetInstance<DanMachiModelBuilder>();

    public override IEnumerator SpawnAsset(Enum assetType, string assetPath, Action<ObjectContainer> callback = null)
    {
        switch (assetType)
        {
            case AssetTypes.Unknown:
                throw new NotImplementedException();
            case AssetTypes.Character:
                var asset = DanMachiAssetLibrary.Instance.Characters.First(c=>c.AssetName == assetPath);
                callback?.Invoke(SpawnCharacter(asset));
                break;
            default:
                throw new NotImplementedException();
        }
        yield break;
    }

    public DanMachiCharacterContainer SpawnCharacter(CharacterAsset asset)
    {
        var container = ObjectContainer.Create<DanMachiCharacterContainer>("Character");
        var handle = UIHandle.CreateAsChild<UIHandleMain>(container.transform).Init(container);
        container.Build(asset);
        container.PlayAnimation(container.Animations[0]);
        return container;
    }
}