using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Runtime.Serialization;
using System.Web;

namespace wijmoSample1.Models.Maps
{
    public enum VectorType
    {
        placemark,
        polyline,
        polygon
    }

    public enum PenLineCap
    {
        butt,
        square,
        round,
    }

    public enum PenLineJoin
    {
        bevel,
        round,
        miter
    }

    [DataContract]
    public abstract class C1VectorItemBase
    {
        private static Color DefaultFill = Color.Transparent;
        private static Color DefaultStroke = Color.Black;

        private IList<PointD> _points = new List<PointD>();

        protected C1VectorItemBase(string type)
        {
            VectorItemType = type;
        }

        [DataMember(Name = "type")]
        public string VectorItemType { get; set; }

        [DataMember(Name = "name", EmitDefaultValue = false)]
        [DefaultValue("")]
        public string Name { get; set; }

        [DataMember(Name = "fill", EmitDefaultValue = false)]
        [DefaultValue("")]
        public string Fill { get; set; }

        [DataMember(Name = "stroke", EmitDefaultValue=false)]
        [DefaultValue(null)]
        public string Stroke { get; set; }

        [DataMember(Name = "strokeWidth", EmitDefaultValue = false)]
        [DefaultValue(1.0d)]
        public double StrokeWidth { get; set; }

        [DataMember(Name = "strokeDashArray", EmitDefaultValue = false)]
        [DefaultValue(null)]
        public string StrokeDashArray { get; set; }

        [DataMember(Name = "strokeLineCap", EmitDefaultValue = false)]
        [DefaultValue("butt")]
        public string StrokeLineCap { get; set; }

        [DataMember(Name = "strokeLineJoin", EmitDefaultValue = false)]
        [DefaultValue("bevel")]
        public string StrokeLineJoin { get; set; }

        [DataMember(Name = "strokeMiterLimit", EmitDefaultValue = false)]
        [DefaultValue(1.0d)]
        public double StrokeMiterLimit { get; set; }

        public IList<PointD> Points
        {
            get
            {
                return _points;
            }
            internal set
            {
                _points = value;
            }
        }

        [DataMember(Name = "coordinates")]
        public IList<double> Coordinates
        {
            get
            {
                if (_points == null) return null;

                var coordinates = new List<double>(_points.Count * 2);
                foreach (var point in _points)
                {
                    coordinates.Add(point.X);
                    coordinates.Add(point.Y);
                }

                return coordinates;
            }
        }
    }

    [DataContract]
    public class C1VectorPlacemark : C1VectorItemBase
    {
        public C1VectorPlacemark()
            : base(VectorType.placemark.ToString())
        {
        }

        [DataMember(Name = "label", EmitDefaultValue = false)]
        [DefaultValue(null)]
        public string Label { get; set; }
    }

    [DataContract]
    public class C1VectorPolyline : C1VectorItemBase
    {
        public C1VectorPolyline()
            : base(VectorType.polyline.ToString())
        {
        }
    }

    [DataContract]
    public class C1VectorPolygon : C1VectorItemBase
    {
        public C1VectorPolygon()
            : base(VectorType.polygon.ToString())
        {
        }
    }
}