using AutoMapper;
namespace FLY.Thick.FilmCasting.Server.Model
{
    public class Lc_AutoMapperProfile : Profile
    {
        public static Mapper Mapper { get; } = new AutoMapper.Mapper(new MapperConfiguration(c =>
        {
            c.CreateMap<Lc_ScanData, Db_ScanData>()
            .ForMember(s => s.Thicks, opt =>
            {
                opt.MapFrom(s => Newtonsoft.Json.JsonConvert.SerializeObject(s.Thicks));
            })
            .ForMember(s => s.SampleADs, opt =>
            {
                opt.MapFrom(s => Newtonsoft.Json.JsonConvert.SerializeObject(s.SampleADs));
            })
            .ForMember(s => s.BoltMapInfo, opt =>
            {
                opt.MapFrom(s => Newtonsoft.Json.JsonConvert.SerializeObject(s.BoltMapInfo));
            })
            .ReverseMap()
            .ForMember(s => s.Thicks, opt =>
            {
                opt.MapFrom(s => Newtonsoft.Json.JsonConvert.DeserializeObject<double[]>(s.Thicks));
            })
            .ForMember(s => s.SampleADs, opt =>
            {
                opt.MapFrom(s => Newtonsoft.Json.JsonConvert.DeserializeObject<int[]>(s.SampleADs));
            })
            .ForMember(s => s.BoltMapInfo, opt =>
            {
                opt.MapFrom(s => Newtonsoft.Json.JsonConvert.DeserializeObject<Lc_BoltMapInfo>(s.BoltMapInfo));
            });




            c.CreateMap<Lc_Sample, Db_Sample>().ForMember(s => s.SampleADs, opt =>
            {
                opt.MapFrom(s => Newtonsoft.Json.JsonConvert.SerializeObject(s.SampleADs));
            }).ReverseMap().ForMember(s => s.SampleADs, opt =>
            {
                opt.MapFrom(s => Newtonsoft.Json.JsonConvert.DeserializeObject<double[]>(s.SampleADs));
            });
        }));
    }
}
