using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Quadarax.Foundation.Core.Data.Entity;
using Quadarax.Foundation.Core.Data.Interface.Entity;

namespace BO.AppServer.Business.Mapper
{
    public static class MapperNoKeyExt
    {
        public static TDto Map<TDao, TDto>(this TDao dao)
            where TDao : class, IDao<NoKey>, new()
            where TDto : class, IDto, new()
        {
            if (dao == null) return null;
            return MapperNoKey.Instance.Map<TDao, TDto>(dao);
        }

        public static TDao MapDto<TDto, TDao>(this TDto dto)
            where TDao : class, IDao<NoKey>, new()
            where TDto : class, IDto, new()
        {
            if (dto == null) return null;
            return MapperNoKey.Instance.Map<TDto, TDao>(dto);
        }

        public static void CopyToDto<TDto, TDao>(this TDto @from, TDao to)
            where TDao : class, IDao<NoKey>, new()
            where TDto : class, IDto, new()
        {
            if (@from == null) return;
            if (to == null) return;
            MapperNoKey.Instance.Update(@from,to);
        }

        public static void CopyToDto<TDto, TDao>(this TDao @from, TDto to)
            where TDao : class, IDao<NoKey>, new()
            where TDto : class, IDto, new()
        {
            if (to == null) return;
            if (@from == null) return;
            MapperNoKey.Instance.Update(@from,to);
        }


        public static List<TDto> MapList<TDao, TDto>(this IQueryable<TDao> dao)
            where TDao : class, IDao<NoKey>, new()
            where TDto : class, IDto, new()
        {
            if (dao == null) return new List<TDto>();
            return MapperNoKey.Instance.MapList<TDao, TDto>(dao);
        }

        public static List<TDto> MapList<TDao, TDto>(this IEnumerable<TDao> dao)
            where TDao : class, IDao<NoKey>, new()
            where TDto : class, IDto, new()
        {
            if (dao == null) return new List<TDto>();
            return MapperNoKey.Instance.MapList<TDao, TDto>(dao);
        }

        public static List<TDto> MapList<TDao, TDto>(this IList<TDao> dao)
            where TDao : class, IDao<NoKey>, new()
            where TDto : class, IDto, new()
        {
            if (dao == null) return new List<TDto>();
            return MapperNoKey.Instance.MapList<TDao, TDto>(dao);
        }

        public static IQueryable<TDao> MapListDto<TDto,TDao>(this IEnumerable<TDto> dto)
            where TDao : class, IDao<NoKey>, new()
            where TDto : class, IDto, new()
        {
            if (dto == null) return new List<TDao>().AsQueryable();
            return MapperNoKey.Instance.MapList<TDto, TDao>(dto.AsQueryable()).AsQueryable();
        }

    }
}
