namespace TeamViewerApi.ViewModels
{
    #region Using
    using System;
    using System.Collections.Generic;
    using System.Linq;
    #endregion

    public class AccountViewModel : BasicViewModel
    {
        #region Properties
        private TeamViewer.Account account;
        #endregion

        #region Constructor
        public AccountViewModel()
        {
            this.Header = "Account";

            this.GetAccountCommand = new Command(this.GetAccount, (o) => 
            {
                return !string.IsNullOrEmpty(TokenViewModel.GetToken());
            });

            this.SaveAccountCommand = new Command(this.SaveAccount, (o) =>
            {
                return this.account != null && !string.IsNullOrEmpty(TokenViewModel.GetToken());
            });
        }
        #endregion

        #region Methods
        /// <summary>
        /// Get current account
        /// </summary>
        private void GetAccount(object o)
        {
            this.Account = TeamViewer.Account.GetAccount(TokenViewModel.GetToken());
        }

        /// <summary>
        /// Save account changes
        /// </summary>
        private void SaveAccount(object o)
        {
            TeamViewer.Account.SaveAccount(TokenViewModel.GetToken(), account);
        }
        #endregion

        #region Public properties
        /// <summary>
        /// Account
        /// </summary>
        public TeamViewer.Account Account
        {
            get { return this.account; }
            private set
            {
                this.account = value;

                this.RaisePropertyChanged(() => this.Account);
            }
        }
        #endregion

        #region Commands
        public Command GetAccountCommand { get; private set; }
        public Command SaveAccountCommand { get; private set; }
        #endregion
    }
}
