
using BaseDomain;
using System.Globalization;

namespace SumaTube.Domain
{
    public class DateChanged : AValueObject
    {
        public DateChanged() 
        {
            this.Value = DateTime.Now;
        }

        public DateChanged(DateTime dateTime)
        {
            this.Value = dateTime;
        }

        public DateChanged(string dateTime)
        {
            this.Value = Convert.ToDateTime(dateTime, new CultureInfo("pt-BR"));
        }

        public DateTime? Value { get; private set; }

        public override bool GetValidationExpression()
        {
            IsValid = true;
            if (Value == null)
            {
                IsValid = false;
            }
            return IsValid;
        }

        protected override IEnumerable<object> GetEqualityComponents()
        {
            yield return Value;
        }

        public static implicit operator string(DateChanged d) => d.Value.Value.ToString("pt-BR");
        public static explicit operator DateChanged(DateTime b) => new DateChanged(b);
        public static explicit operator DateChanged(string b) => new DateChanged(b);
    }
}
