using AutoMapper;
using FLY.Thick.FilmCasting.Server.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FLY.FilmCasting.AutoDie.Server.Model
{
    /// <summary>
    /// LC 与 DB 类的映射关系
    /// </summary>
    public class Lc_AutoMapperProfile : AutoMapper.Profile
    {
        public static Mapper Mapper { get; } = new AutoMapper.Mapper(new MapperConfiguration(c =>
        {
            c.CreateMap<Lc_ThickHeat, Db_ThickHeat>()
            .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));
            })
            .ForMember(s => s.Boltmap, opt =>
            {
                opt.MapFrom(s => Newtonsoft.Json.JsonConvert.SerializeObject(s.Boltmap));
            })
            .ForMember(s => s.Heats, opt =>
            {
                opt.MapFrom(s => Newtonsoft.Json.JsonConvert.SerializeObject(s.Heats));
            })
            .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));
            })
            .ForMember(s => s.Boltmap, opt =>
            {
                opt.MapFrom(s => Newtonsoft.Json.JsonConvert.DeserializeObject<List<BoltMapCell>>(s.Boltmap));
            })
            .ForMember(s => s.Heats, opt =>
            {
                opt.MapFrom(s => Newtonsoft.Json.JsonConvert.DeserializeObject<int[]>(s.Heats));
            });
        }));
    }
}
