using GreenTree.Nachtragsmanagement.Core;
using GreenTree.Nachtragsmanagement.Core.Plugins;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace GreenTree.Nachtragsmanagement.Web.Models.Admin.Plugins
{
    public class PluginDataModel
    {
        public bool IsInstalled { get; set; }
        public string SystemName { get; set; }
        public string FriendlyName { get; set; }
        public string LogoUrl { get; set; }
        public string Group { get; set; }
        public string Author { get; set; }
        public string Version { get; set; }

        public static PluginDataModel FromPluginDesciptor(PluginDescriptor descriptor, IWebHelper webHelper)
        {
            if (descriptor == null)
                throw new ArgumentNullException("descriptor", "Cannot create PluginDataModel from NULL plugin descriptor.");

            return new PluginDataModel
            {
                IsInstalled = descriptor.Installed,
                SystemName = descriptor.SystemName,
                FriendlyName = descriptor.FriendlyName,
                LogoUrl = descriptor.GetLogoUrl(webHelper),
                Group = descriptor.Group,
                Author = descriptor.Author,
                Version = descriptor.Version
            };
        }
    }
}