package cn.pluss.platform.converter;

import cn.pluss.platform.annotation.ToEntity;
import cn.pluss.platform.entity.MerchantBaseInfo;
import cn.pluss.platform.entity.MerchantStore;
import cn.pluss.platform.entity.UserApp;
import cn.pluss.platform.entity.UserInfo;
import org.mapstruct.*;
import org.mapstruct.factory.Mappers;

/**
 * @author DJH
 */
@Mapper(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
public interface UserAppConverter {
    UserAppConverter INSTANCE = Mappers.getMapper(UserAppConverter.class);

    /**
     * 复制属性
     *
     * @param merchantStore 源数据对象
     * @param userApp       目标对象
     */
    @Mapping(source = "id", target = "storeId2")
    @Mapping(target = "status", ignore = true)
    @ToEntity
    void copyProperties(MerchantStore merchantStore, @MappingTarget UserApp userApp);

    /**
     * 复制属性
     *
     * @param merchantBaseInfo 源数据对象
     * @param userApp          目标对象
     */
    @Mapping(source = "alias", target = "merchantName")
    @Mapping(source = "id", target = "mercId")
    @Mapping(target = "status", ignore = true)
    @ToEntity
    void copyProperties(MerchantBaseInfo merchantBaseInfo, @MappingTarget UserApp userApp);

    /**
     * 对象属性转换
     * @param userInfo  用户信息
     * @return
     */
    @Mapping(source = "createTime", target = "createDt")
    @Mapping(source = "id", target = "userId")
    @Mapping(target = "id", ignore = true)
    UserApp toUserApp(UserInfo userInfo);
}
