using Earthblend.Tts.Common.Core.Enumerations;
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Xml.Serialization;

namespace Earthblend.Tts.Common.Core.Members
{
    public class DataItem3D : ImageDataItem
    {
        private ObservableCollection<Member> _memberOf = new ObservableCollection<Member>();
        public ObservableCollection<Member> MemberOf { get { return _memberOf; } set { SetProperty(ref _memberOf, value); } }

        public Boolean HasMember(String member)
        {
            if (MemberOf == null) return false;
            if (!MemberOf.Any()) return false;
            Boolean ret = false;
            foreach (var x in MemberOf)
            {
                if (x.Name == member)
                {
                    ret = true;
                    break;
                }
            }

            return ret;
        }

        public DataItem3D Duplicate()
        {
            var dataItem3D = new DataItem3D()
            {
                PosX = PosX
                ,
                PosY = PosY
                ,
                PosZ = PosZ
                ,
                MeshColor = MeshColor
                ,
                MeshType = MeshType
            };

            return dataItem3D;
        }

        #region Private Variables

        private Object _shape = null;
        private Double _posX = 0.0D;
        private Double _posY = 0.0D;
        private Double _posZ = 0.0D;


        private String _meshType = "Box";
        private String _meshColor = "SeaGreen";
        private Guid _associatedGuid = Guid.Empty;
        private Guid _parentGroupId = Guid.Empty;
        private String _group = "None";
        private Boolean _useBackBrush = false;
        private Boolean _mirrorLabel = false;
        private MeshBrushType _brushType = MeshBrushType.Solid;

        #endregion

        [XmlIgnore]
        public String Type { get { return Shape == null ? "Null" : Shape.GetType().ToString(); } }

        #region Public Clr Properties
        public Object Shape { get { return _shape; } set { SetProperty(ref _shape, value); NotifyPropertyChanged("Type"); NotifyPropertyChanged("ActualType"); } }

        public Double PosX { get { return _posX; } set { SetProperty(ref _posX, value); } }
        public Double PosY { get { return _posY; } set { SetProperty(ref _posY, value); } }
        public Double PosZ { get { return _posZ; } set { SetProperty(ref _posZ, value); } }

        public Boolean UseBackBrush { get { return _useBackBrush; } set { SetProperty(ref _useBackBrush, value); } }
        public Boolean MirrorLabel { get { return _mirrorLabel; } set { SetProperty(ref _mirrorLabel, value); } }

        public Guid AssociatedGuid { get { return _associatedGuid; } set { SetProperty(ref _associatedGuid, value); } }
        public String MeshColor { get { return _meshColor; } set { SetProperty(ref _meshColor, value); } }
        public Guid ParentGroupId { get { return _parentGroupId; } set { SetProperty(ref _parentGroupId, value); } }
        public String Group { get { return _group; } set { SetProperty(ref _group, value); } }

        public String MeshType
        {
            get { return _meshType; }
            set
            {
                SetProperty(ref _meshType, value);
            }
        }
        public MeshBrushType BrushType { get { return _brushType; } set { SetProperty(ref _brushType, value); } }

        #endregion

        #region Public Methods

        public void SetPosXWithoutUpdate(Double d)
        {
            _posX = d;
        }
        public void SetPosYWithoutUpdate(Double d)
        {
            _posY = d;
        }
        public void SetPosZWithoutUpdate(Double d)
        {
            _posZ = d;
        }

        #endregion

    }
}