using AutoMapper;
using IRaCIS.Application.Contracts;
using IRaCIS.Core.Application.Contracts;
using IRaCIS.Core.Application.ViewModel;
using IRaCIS.Core.Domain.Models;

namespace IRaCIS.Core.Application.Service
{
    public class CommonConfig : Profile
    {
        public CommonConfig()
        {
            CreateMap<Message, SysMessageDTO>()
              .ForMember(o => o.MessageTime, t => t.MapFrom(u => u.MessageTime.ToString()));

            CreateMap<SystemLog, SystemLogDTO>();

            CreateMap<SystemLogDTO, SystemLog>();

            CreateMap<FrontAuditConfig, FrontAuditConfigAddOrEdit>().ReverseMap();

            CreateMap<EmailNoticeConfigAddOrEdit, EmailNoticeConfig>().ReverseMap();
            CreateMap<EmailNoticeConfig, EmailNoticeConfigView>();


            CreateMap<SystemBasicData, SystemBasicDataView>();

            CreateMap<SystemBasicData, SystemBasicDataSelect>()
                 .ForMember(o => o.ParentCode, t => t.MapFrom(u => u.Parent.Code));

            CreateMap<SystemBasicDataAddOrEdit, SystemBasicData>().ReverseMap();



            CreateMap<Dictionary, BasicDicView>()
                 .ForMember(o => o.ConfigType, t => t.MapFrom(u => u.ConfigDictionary.Code));

            CreateMap<AddOrEditBasicDic, Dictionary>().ReverseMap();


            CreateMap<Dictionary, BasicDicSelect>()
                 .ForMember(o => o.ParentChildCodeEnum, t => t.MapFrom(u => u.Parent.ChildCodeEnum))
                
                 .ForMember(o => o.ParentCode, t => t.MapFrom(u => u.Parent.Code));

            var token = "";
            CreateMap<CommonDocument, CommonDocumentView>()
                .ForMember(o => o.FileType, t => t.MapFrom(u => u.FileType.Value))
                .ForMember(o => o.ModuleType, t => t.MapFrom(u => u.ModuleType.Value))
                 .ForMember(d => d.FullFilePath, u => u.MapFrom(s => s.Path + "?access_token=" + token));

            CreateMap<CommonDocument, CommonDocumentAddOrEdit>().ReverseMap();

            
        }
    }
   
}