using System;
using System.Collections.Generic;
using KellermanSoftware.NetDataAccessLayer.Attributes;

namespace KellermanSoftware.ContactsModule.Models
{
    public class Contact
    {
        public int ContactId { get; set; }
        public string Name { get; set; }
        public string Address { get; set; }
        public string City { get; set; }
        public string State { get; set; }
        public string PostalCode { get; set; }
        public string Country { get; set; }
        public string Email { get; set; }
        public string Phone { get; set; }

        public Contact()
        {
            History = new List<ContactHistory>();
        }

        public Contact(Contact other)
        {
            ContactId = other.ContactId;
            Name = other.Name;
            Address = other.Address;
            City = other.City;
            State = other.State;
            PostalCode = other.PostalCode;
            Country = other.Country;
            Email = other.Email;
            Phone = other.Phone;
            History = new List<ContactHistory>(other.History);
        }

        //One to Many Relationship
        [ChildObject("ContactId")]
        public List<ContactHistory> History { get; set; }

        public Tuple<bool, string> ValidateName()
        {
            if (string.IsNullOrEmpty(Name))
            {
                return new Tuple<bool, string>(false, "Name is required");
            }
            return new Tuple<bool, string>(true, null);
        }
    }
}
