package com.seer.teach.user.convert;

import com.seer.teach.common.dto.mq.im.MqUserInfoDTO;
import com.seer.teach.user.api.dto.*;
import com.seer.teach.user.entity.*;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.List;

@Mapper
public interface UserInfoConvert {

    UserInfoConvert INSTANCE = Mappers.getMapper(UserInfoConvert.class);

    UserInfoDTO convertOne(UserEntity entity);

    List<UserInfoDTO> convertList(List<UserEntity> list);

    List<UserDeviceDTO> convertUserDeviceList(List<UserEntity> list);

    UserAuthDTO convertUserAuthOne(UserAuthEntity entity);

    List<UserAuthDTO> convertUserAuthList(List<UserAuthEntity> list);

    @Mapping(source = "entity.id", target = "id")
    UserInfoDTO convertOne(UserEntity entity, UserExtendEntity userExtendEntity);

    /**
     * dto 转 entity
     *
     * @param dto
     * @return
     */
    UserEntity convertOne(UserInfoDTO dto);

    @Mapping(source = "permissions", target = "permissions")
    @Mapping(source = "userEntity", target = "userInfo")
    @Mapping(source = "userEntity.password",target = "userInfo.password", ignore = true)
    UserPermissionDTO convertUserPermissionList(UserEntity userEntity, List<AuthorityEntity> permissions);

    @Mapping(source = "level.imageUrl", target = "levelImageUrl")
    @Mapping(source = "level.name", target = "currentLevel")
    @Mapping(source = "children.id", target = "id")
    MqUserInfoDTO toMqUserInfoDTO(UserEntity children, UserExtendEntity userExtendEntity, GradeEntity grade, LevelEntity level, String device);

    ChildrenInfoDTO toChildrenInfoDTO(Integer id, String nickName, String grade, String avatar, String currentLevel, Integer experience, String levelImageUrl,Integer coinNumber);
}