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

namespace DigitalData.UserManager.Application.MappingProfiles
{
    public class GroupMappingProfile : Profile
    {
        public GroupMappingProfile()
        {
            CreateMap<Group, GroupCreateDto>();
            CreateMap<Group, GroupReadDto>();
            CreateMap<Group, GroupUpdateDto>();

            CreateMap<GroupCreateDto, Group>();
            CreateMap<GroupReadDto, Group>();
            CreateMap<GroupUpdateDto, Group>();

            CreateMap<DirectoryGroupDto, Group>()
                .ForMember(group => group.EcmFkId, opt => opt.MapFrom(adGroup => 1))
                .ForMember(group => group.AdSync, opt => opt.MapFrom(adGroup => true))
                .ForMember(group => group.Internal, opt => opt.MapFrom(adGroup => false))
                .ForMember(group => group.Active, opt => opt.MapFrom(adGroup => true))
                .ForMember(group => group.Name, opt => opt.MapFrom(adGroup => adGroup.Samaccountname.ElementAt(0)));
        }
    }
}