﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Devices.Enumeration;
using Windows.Media.Capture;

namespace WebcamApp.ViewModels
{
    public class MainViewModel : ViewModelBase
    {
        private string _appTitle = "The Webcam App";

        private DeviceInformationCollection _videoCaptureDevices;

        public string AppTitle
        {
            get
            {
                return _appTitle;
            }

            set
            {
                _appTitle = value;
            }
        }
        
        public AppSettings AppSettings
        {
            get
            {
                return AppSettings.Instance;
            }
        }

        public List<DeviceInformation> VideoCaptureDevices
        {
            get
            {
                if (Windows.ApplicationModel.DesignMode.DesignModeEnabled)
                {
                    return null;
                }
                if (_videoCaptureDevices == null)
                {
                    _videoCaptureDevices = GetVideoCaptureDevices().GetAwaiter().GetResult();
                }

                return _videoCaptureDevices.ToList();
            }
            internal set
            {
                //_videoCaptureDevices = value;
            }
        }
        

        public async Task<DeviceInformationCollection> GetVideoCaptureDevices()
        {
            var devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
            return devices;
        }

    }
}
