using AutoMapper.EquivalencyExpression;
using IRaCIS.Core.Application.Service;
using IRaCIS.Core.Domain.Models;
using Microsoft.Extensions.DependencyInjection;

namespace IRaCIS.Core.API
{
    public static class AutoMapperSetup
    {
        public static void AddAutoMapperSetup(this IServiceCollection services)
        {

            services.AddAutoMapper(automapper =>
            {
                //AutoMapper.Collection.EntityFrameworkCore
                automapper.AddCollectionMappers();


                // 全局忽略 DomainEvents 属性
                automapper.AddGlobalIgnore(nameof(Entity.DomainEvents));
                automapper.AddGlobalIgnore(nameof(Entity.DomainCommands));

                #region 会使  IncludeMembers 失效 不能全局使用
                //mapping an EntityFramework Core DbContext-object.
                //automapper.UseEntityFrameworkCoreModel<IRaCISDBContext>(services);


                //automapper.ForAllMaps((a, b) => b.ForAllMembers(opt => opt.Condition((src, dest, srcMember, desMenber) =>
                //{
                //    //// Can test  When Guid? -> Guid  if source is null  will change to Guid.Empty
                //    //Console.WriteLine("srcMember:" + srcMember + "desMenber:" + desMenber);
                //    return srcMember != null && srcMember.ToString() != Guid.Empty.ToString();
                //    // not want to map a null Guid? value to db Guid value
                //})));
                #endregion

            }, typeof(QCConfig).Assembly);


        }
    }
}
