package com.ichangzuo.system.converter;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ichangzuo.system.model.entity.User;
import com.ichangzuo.system.model.vo.UserInfoVO;
import com.ichangzuo.system.model.vo.UserPageVO;
import com.ichangzuo.system.model.vo.UserProfileVO;
import com.ichangzuo.system.model.bo.UserBO;
import com.ichangzuo.system.model.form.UserForm;
import com.ichangzuo.system.model.dto.UserImportDTO;
import com.ichangzuo.system.model.form.UserProfileForm;
import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

/**
 * 用户对象转换器
 *
 * @author haoxr
 * @since 2022/6/8
 */
@Mapper(componentModel = "spring")
public interface UserConverter {

    @Mappings({
            @Mapping(target = "genderLabel",
                    expression = "java("
                                + "com.ichangzuo.common.base.IBaseEnum.getLabelByValue("
                                    + "bo.getGender()!=null && bo.getGender()>0 ? bo.getGender():5, "
                                    + "com.ichangzuo.common.enums.GenderEnum.class"
                                + "))")
    })
    UserPageVO toPageVo(UserBO bo);

    Page<UserPageVO> toPageVo(Page<UserBO> bo);

    UserForm toForm(User entity);

    @InheritInverseConfiguration(name = "toForm")
    User toEntity(UserForm entity);

    @Mappings({
            @Mapping(target = "userId", source = "id")
    })
    UserInfoVO toUserInfoVo(User entity);

    User toEntity(UserImportDTO vo);


    UserProfileVO toProfileVO(UserBO bo);

    User toEntity(UserProfileForm formData);
}
