package com.eactive.httpmockserver.user.mapper;


import com.eactive.httpmockserver.common.mapper.CommonMapper;
import com.eactive.httpmockserver.common.util.EncryptionUtil;
import com.eactive.httpmockserver.user.dto.UserRegisterDTO;
import com.eactive.httpmockserver.user.dto.UserUpdateDTO;
import com.eactive.httpmockserver.user.entity.StaffUser;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.ReportingPolicy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Mapper(componentModel = "spring",
        uses = {CommonMapper.class},
        unmappedTargetPolicy = ReportingPolicy.IGNORE)
@Component
public abstract class StaffUserMapper {

    @Autowired
    private EncryptionUtil encryptionUtil;

    @Mapping(target = "password", expression = "java(mapPassword(dto))")
    public abstract StaffUser map(UserRegisterDTO dto);

    public abstract StaffUser map(UserUpdateDTO dto);


    public String mapPassword(UserRegisterDTO dto) {
        return encryptionUtil.encryptPassword(dto.getPassword(), dto.getUserId());
    }
}

