using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SearchContract.Data
{
    public sealed class CustomerDataSource
    {
        private static CustomerDataSource _customerDataSource = new CustomerDataSource();

        private ObservableCollection<Customer> _allCustomers = new ObservableCollection<Customer>();
        public ObservableCollection<Customer> AllCustomers
        {
            get { return this._allCustomers; }
        }

        public static IEnumerable<Customer> GetCustomers()
        {
            return _customerDataSource.AllCustomers;
        }

        public CustomerDataSource()
        {
            // create an observable list of customers
            for (int i = 0; i < 1000; i++)
                this.AllCustomers.Add(new Customer());
        }

    }

    public class Customer : Common.BindableBase
    {
        int _id;
        string _name, _country;
        DateTime _created;
        double _value, _sales, _assets, _growth;
        bool _active;

        static int _ctr;
        static Random _rnd = new Random(0);
        static string[] _countries = "Austria|Belgium|Canada|Denmark|Egypt|Finland|Guatemala|Haiti|Ireland|Jamaica".Split('|');
        static string[] _names = "Albert|Bill|Charlie|Dave|Ed|Fred|George|Harry|Ian|Jerry".Split('|');

        public Customer()
        {
            ID = _ctr++;
            Name = _names[_rnd.Next() % _names.Length];
            Country = _countries[_rnd.Next() % _countries.Length];
            Created = DateTime.Today.AddDays(_rnd.Next(-3000, -30));
            for (int i = 0; i < 100; i++)
            {
                Assets += _rnd.NextDouble() * 100;
                Value += _rnd.NextDouble() * 1000;
                Sales += _rnd.NextDouble() * 100;
            }
            if (_rnd.NextDouble() < .05)
            {
                Value = -Value;
                Assets = -Assets;
            }
            if (_rnd.NextDouble() < .05)
            {
                Growth = -Growth;
            }
            Growth = _rnd.NextDouble();
            Active = _rnd.NextDouble() > .5;
        }

        [Display(Name = "ID")]
        public int ID
        {
            get { return _id; }
            set { SetProperty(ref _id, value, "ID"); }
        }

        [Display(Name = "Name")]
        public string Name
        {
            get { return _name; }
            set { SetProperty(ref _name, value, "Name"); }
        }

        [Display(Name = "Country")]
        public string Country
        {
            get { return _country; }
            set { SetProperty(ref _country, value, "Country"); }
        }

        [Display(Name = "Created")]
        public DateTime Created
        {
            get { return _created; }
            set { SetProperty(ref _created, value, "Created"); }
        }

        [Display(Name = "Sales")]
        public double Sales
        {
            get { return _sales; }
            set { SetProperty(ref _sales, value, "Sales"); }
        }

        [Display(Name = "Growth")]
        public double Growth
        {
            get { return _growth; }
            set { SetProperty(ref _growth, value, "Growth"); }
        }

        [Display(Name = "Assets")]
        public double Assets
        {
            get { return _assets; }
            set { SetProperty(ref _assets, value, "Assets"); }
        }

        [Display(Name = "Value")]
        public double Value
        {
            get { return _value; }
            set { SetProperty(ref _value, value, "Value"); }
        }

        [Display(Name = "Active")]
        public bool Active
        {
            get { return _active; }
            set { SetProperty(ref _active, value, "Active"); }
        }
    }
}
