﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Hydra.Framework;
using Hydra.Framework.Helpers;
using Hydra.Framework.Conversions;
using DataModel = Hydra.Data.Model;
using DomainModel = Hydra.DomainModel;

namespace Hydra.Domain.Mapping
{
    public class GPSMarkerMapping
        : IEntityMapper<DataModel.GPSMarker, DomainModel.InternalGPSMarker>
    {
        #region Implementation of IEntityMapper
        /// <summary>
        /// Convert Domain Model Entity to Data Model Entity
        /// </summary>
        /// <param name="entity">Domain Model Entity</param>
        /// <returns></returns>
        public DataModel.GPSMarker MapDomainEntityToDataEntity(DomainModel.InternalGPSMarker entity)
        {
            DataModel.GPSMarker item = entity == null
                ? null
                : new DataModel.GPSMarker()
                {
                    ID = entity.ID,
                    ObjectId = entity.ObjectID,
                    Name = entity.Name,
                    Description = entity.Description,
                    ChangedOn = entity.ChangedOn,
                    LatitudeDegrees = (entity.Latitude != null && entity.Latitude.Count == 3 ? entity.Latitude[0] : 0.0F),
                    LatitudeMinutes = (entity.Latitude != null && entity.Latitude.Count == 3 ? entity.Latitude[1] : 0.0F),
                    LatitudeSeconds = (entity.Latitude != null && entity.Latitude.Count == 3 ? entity.Latitude[2] : 0.0F),
                    LongitudeDegrees = (entity.Longitude != null && entity.Longitude.Count == 3 ? entity.Longitude[0] : 0.0F),
                    LongitudeMinutes = (entity.Longitude != null && entity.Longitude.Count == 3 ? entity.Longitude[1] : 0.0F),
                    LongitudeSeconds = (entity.Longitude != null && entity.Longitude.Count == 3 ? entity.Longitude[2] : 0.0F),
                    Altitude = entity.Altitude,
                    AltitudeType = entity.AltitudeType,
                    Datum = entity.Datum,
                    X = entity.PointX,
                    Y = entity.PointY,
                    Z = entity.PointZ,
                };

            // Nullable
            if (item != null)
            {
                if (entity.LocationId > 0)
                    item.LocationID = entity.LocationId;
                if (entity.ParentID > 0)
                    item.ParentId = entity.ParentID;
            }

            return item;
        }

        /// <summary>
        /// Convert Data Model Entity to Domain Model Entity
        /// </summary>
        /// <param name="entity">Data Model Entity</param>
        /// <returns>Domain Model Entity</returns>
        public DomainModel.InternalGPSMarker MapDataEntityToDomainEntity(DataModel.GPSMarker entity)
        {
            return entity == null
                ? null
                : new DomainModel.InternalGPSMarker()
                {
                    ID = entity.ID,
                    ObjectID = NullableConversion.Convert(entity.ObjectId),
                    LocationId = entity.LocationID,
                    Name = entity.Name,
                    Description = entity.Description,
                    ChangedOn = NullableConversion.Convert(entity.ChangedOn),
                    Latitude = NullableConversion.Convert(entity.LatitudeDegrees, entity.LatitudeMinutes, entity.LatitudeSeconds),
                    Longitude = NullableConversion.Convert(entity.LongitudeDegrees, entity.LongitudeMinutes, entity.LongitudeSeconds),
                    Altitude = NullableConversion.Convert(entity.Altitude),
                    AltitudeType = NullableConversion.Convert(entity.AltitudeType),
                    Datum = NullableConversion.Convert(entity.Datum),
                    PointX = NullableConversion.Convert(entity.X),
                    PointY = NullableConversion.Convert(entity.Y),
                    PointZ = NullableConversion.Convert(entity.Z),
                    ParentID = NullableConversion.Convert(entity.ParentId)
                };
        }
        #endregion

        #region Private Methods
        #endregion
    }
}