using AutoMapper;
using AutoMapper.Configuration;
using System;

namespace VCommon.VAutoMapper.Internals
{
    internal class VAutoMapperConfiguration
    {
        public MapperConfigurationExpression AutoMapperConfiguration { get; } = new MapperConfigurationExpression();

        public IConfigurationProvider Config { get; private set; }

        public IMapper Mapper { get; private set; }

        public IMappingExpression CreateMap(Type s, Type d) => AutoMapperConfiguration.CreateMap(s, d, MemberList.Source);

        public void FlushMapper()
        {
            Config = new MapperConfiguration(AutoMapperConfiguration);
            Mapper = new Mapper(Config);
        }
    }
}