using AutoMapper;
using Newtonsoft.Json;
using System;

// https://docs.automapper.org/en/latest/Getting-started.html
// https://docs.automapper.org/en/latest/

namespace TopNugetPackages
{
    // class object containing the source of data
    public class AutoMapper_Source
    {
        public string firstName { get; set; }
        public string lastName { get; set; }
        public int age { get; set; }
        public DateTime birthDate { get; set; }
    }

    // class object that will receive/inherit some or partially some data from the source class
    public class AutoMapper_Destination
    {
        public string firstName { get; set; }
        public string lastName { get; set; }
        public int age { get; set; }
        public string address { get; set; }
        public double gpa { get; set; }
    }

    // Main driver to map class data from source class to destination class
    public class MainAutoMapperDriver
    {
        private MapperConfiguration mapperConfig = null;

        public MainAutoMapperDriver() 
        {
            // should be done once per domain, such as in app constructor
            mapperConfig = new MapperConfiguration(cfg => cfg.CreateMap<AutoMapper_Source, AutoMapper_Destination>());
        }

        public void MapObjects()
        {
            var src = new AutoMapper_Source()
            {
                firstName = "Tim",
                lastName = "Hsu",
                age = 40,
                birthDate = DateTime.FromFileTime(257299200)
            };

            var mapper = new Mapper(mapperConfig);
            var dest = mapper.Map<AutoMapper_Destination>(src);

            // now lets check it
            var json = JsonConvert.SerializeObject(dest, Formatting.Indented);
            Console.WriteLine(json);
        }
    }
}