﻿using System;
using System.Collections.Generic;
using System.Text;
using DatabaseInspector.Contracts.ServiceLibrary.DTO;
using Entities = DatabaseInspector.Library.Entities;
using System.Linq;

namespace DatabaseInspector.Impl.ServiceLibrary.Mappers.Map.DtoToEntity
{
    public class ContraintDtoToEntity
    {
        public Entities.Constraint To(Constraint obj)
        {
            if (obj == null) return null;

            return new Entities.Constraint
            {
                Name = obj.Name,
                ParentSchemaName = obj.ParentSchemaName,
                ParentTableName = obj.ParentTableName,
                ParentColumnName = obj.ParentColumnName,
                ReferencedSchemaName = obj.ReferencedSchemaName,
                ReferencedTableName = obj.ReferencedTableName,
                ReferencedColumnName = obj.ReferencedColumnName,
                DeleteReferentialType = obj.DeleteReferentialType,
                UpdateReferentialType = obj.UpdateReferentialType,
                Type = (Library.Enums.ConstraintType)Enum.Parse(typeof(Library.Enums.ConstraintType), Enum.GetName(typeof(Contracts.ServiceLibrary.Enums.ConstraintType), obj.Type))
            };
        }

        public IEnumerable<Entities.Constraint> ToCollection(IEnumerable<Constraint> collection)
        {
            return collection.Select(To);
        }
    }
}
