using System;
using Windows.Devices.Enumeration;
using System.ComponentModel;
using Windows.UI.Xaml.Media.Imaging;

namespace WinRT.BxlComponent.Plugin.BxlMpXamarinSDK
{
    internal class MPosRfcommDevice : INotifyPropertyChanged
    {
        private DeviceInformation deviceInfo;

        public MPosRfcommDevice(DeviceInformation deviceInfoIn)
        {
            deviceInfo = deviceInfoIn;
            //UpdateGlyphBitmapImage();
        }
        public DeviceInformation DeviceInformation
        {
            get { return deviceInfo; }
            private set { deviceInfo = value; }
        }
        public string Id
        {
            get { return deviceInfo.Id; }
        }
        public string Name
        {
            get { return deviceInfo.Name; }
        }
        public BitmapImage GlyphBitmapImage
        {
            get;
            private set;
        }

        public void Update(DeviceInformationUpdate deviceInfoUpdate)
        {
            deviceInfo.Update(deviceInfoUpdate);
            //UpdateGlyphBitmapImage();
        }

        private async void UpdateGlyphBitmapImage()
        {
            DeviceThumbnail deviceThumbnail = await deviceInfo.GetGlyphThumbnailAsync();
            BitmapImage glyphBitmapImage = new BitmapImage();
            await glyphBitmapImage.SetSourceAsync(deviceThumbnail);
            GlyphBitmapImage = glyphBitmapImage;
            OnPropertyChanged("GlyphBitmapImage");
        }

        public event PropertyChangedEventHandler PropertyChanged;
        protected void OnPropertyChanged(string name)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(name));
            }
        }
    }
}