using AutoMapper;
using DigitalData.UserManager.Application.DTOs.User;
using DigitalData.UserManager.Domain.Entities;

namespace DigitalData.UserManager.Application.MappingProfiles
{
    public class UserMappingProfile : Profile
    {
        public UserMappingProfile()
        {
            CreateMap<User, UserCreateDto>();
            CreateMap<User, UserReadDto>();
            CreateMap<User, UserUpdateDto>();

            CreateMap<UserCreateDto, User>();
            CreateMap<UserReadDto, User>();
            CreateMap<UserUpdateDto, User>();

            CreateMap<UserPrincipalDto, User>()
                .ForMember(user => user.Name, opt => opt.MapFrom(upDto => upDto.Surname))
                .ForMember(user => user.Prename, opt => opt.MapFrom(upDto => upDto.GivenName))
                .ForMember(user => user.Username, opt => opt.MapFrom(upDto => upDto.SamAccountName))
                .ForMember(user => user.Email, opt => opt.MapFrom(upDto => upDto.EmailAddress));
        }
    }
}