using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.ComponentModel;

namespace TwitterClient
{
    /// <summary>
    /// Interaction logic for PinDialogBox.xaml
    /// </summary>
    public partial class PinDialogBox : Window, IDataErrorInfo, INotifyPropertyChanged
    {
        public static readonly DependencyProperty IsValidProperty = DependencyProperty.Register(
        "IsValid", typeof(String), typeof(PinDialogBox));

        public PinDialogBox()
        {
            InitializeComponent();
            IsValid = "False";
        }
        
        public String Pin { get; set; }
        public String IsValid
        {
            get { return (String)GetValue(PinDialogBox.IsValidProperty); }
            set { SetValue(PinDialogBox.IsValidProperty, value); }
        }

        private void ButtonOk_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }



        public string Error
        {
            get { return null; }
        }

        public string this[string columnName]
        {
            get
            {
                string result = null;
                IsValid = "True";

                if (columnName == "Pin")
                {
                    try
                    {
                        Convert.ToInt64(Pin);
                    }
                    catch (FormatException)
                    {
                        IsValid = "False";
                        result = "Wartość musi być liczbą";
                    }
                }
                return result;
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        public void OnPropertyChanged(PropertyChangedEventArgs e)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, e);
        }

    }
}
