using System;
using System.Runtime.Serialization;

namespace GitHub.Services.Profile
{
    [DataContract]
    public class Avatar : ITimeStamped, ICloneable
    {
        [DataMember]
        public byte[] Value { get; set; }

        [DataMember(IsRequired = false, EmitDefaultValue = false)]
        public DateTimeOffset TimeStamp { get; set; }

        [DataMember(IsRequired = false, EmitDefaultValue = false)]
        public AvatarSize Size { get; internal set; }

        [DataMember(IsRequired = false, EmitDefaultValue = false)]
        public bool? IsAutoGenerated { get; internal set; }

        public object Clone()
        {
            var clone = new Avatar()
            {
                Size = this.Size,
                TimeStamp = this.TimeStamp,
                IsAutoGenerated = this.IsAutoGenerated
            };
            if (Value != null)
            {
                clone.Value = new byte[Value.Length];
                Buffer.BlockCopy(Value, 0, clone.Value, 0, Value.Length);
            }
            return clone;
        }
    }

    /// <summary>
    /// Small = 34 x 34 pixels; Medium = 44 x 44 pixels; Large = 220 x 220 pixels
    /// </summary>
    [DataContract]
    public enum AvatarSize
    {
        Small,
        Medium,
        Large,
    }
}
