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

namespace BasicLibrarySamples
{
    public class Customer : BaseEditableObject
    {
        int _id;
        string _name, _country;
        DateTime _created;
        double _value, _sales, _assets, _growth;
        bool _active;

        static int _ctr;
        static Random _rnd = new Random();
        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 static ObservableCollection<Customer> GetCollection(int count)
        {
            ObservableCollection<Customer> ret = new ObservableCollection<Customer>();
            for (int i = 0; i < count; i++)
                ret.Add(new Customer());
            return ret;
        }

        public Customer()
        {
            ID = _ctr++;
            Name = _names[_rnd.Next() % _names.Length];
            Country = _countries[_rnd.Next() % _countries.Length];
            Created = DateTime.Today.AddDays(_rnd.Next(-40, -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;
        }
        public int ID
        {
            get { return _id; }
            set { SetValue(ref _id, value, "ID"); }
        }
        public string Name
        {
            get { return _name; }
            set { SetValue(ref _name, value, "Name"); }
        }
        public string Country
        {
            get { return _country; }
            set { SetValue(ref _country, value, "Country"); }
        }
        public DateTime Created
        {
            get { return _created; }
            set { SetValue(ref _created, value, "Created"); }
        }
        public double Sales
        {
            get { return _sales; }
            set { SetValue(ref _sales, value, "Sales"); }
        }
        public double Growth
        {
            get { return _growth; }
            set { SetValue(ref _growth, value, "Growth"); }
        }
        public double Assets
        {
            get { return _assets; }
            set { SetValue(ref _assets, value, "Assets"); }
        }
        public double Value
        {
            get { return _value; }
            set { SetValue(ref _value, value, "Value"); }
        }
        public bool Active
        {
            get { return _active; }
            set { SetValue(ref _active, value, "Active"); }
        }
    }
}
