using Ion.Sdk.Ici;
using Ion.Sdk.Idi;
using System.Linq;
using System.Threading.Tasks;

namespace Ion.Sdk.DemoApp.Components
{
    public abstract class WorkspaceFileLoader : FileLoader<Workspace>
    {

        #region -=Loader implementations=-

        public class Padfx : WorkspaceFileLoader
        {
            public override string CommandName { get; } = "Open";
            public override string OpenDialogFilter => "padfx|*.padfx";
            public override async Task<Workspace> Load(string file)
            {
                Workspace workspace = null;
                using (var padfx = Channel.Padfx.Open(file))
                {
                    padfx.Use(Progress);
                    var workspaceInfo = (await padfx.GetWorkspaces()).FirstOrDefault();
                    workspace = await padfx.DownloadWorkspace(workspaceInfo);
                }
                return workspace;
            }
        }

        #endregion
    }
}
