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

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

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

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

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


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

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

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

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

    }
}
