package com.jeesharp.business.modules.mall.convert;

import com.jeesharp.business.modules.mall.dto.MallBrowseFootprintSaveDTO;
import com.jeesharp.business.modules.mall.entity.MallBrowseFootprint;
import com.jeesharp.business.modules.mall.vo.MallBrowseFootprintInfoVO;
import com.jeesharp.business.modules.mall.vo.MallBrowseFootprintListVO;
import com.jeesharp.business.modules.mall.vo.MallBrowseFootprintQueryVO;
import com.jeesharp.framework.common.pojo.convert.BasePojoConvert;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

/**
 * 浏览足迹 MapStruct 转换器。
 *
 * @author jeesharp
 * @since 2026-06-05
 */
@Mapper
public interface MallBrowseFootprintConvert extends BasePojoConvert<MallBrowseFootprint, MallBrowseFootprintSaveDTO, MallBrowseFootprintInfoVO, MallBrowseFootprintListVO, MallBrowseFootprintQueryVO> {

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

    @Override
    @Mapping(target = "memberNo", ignore = true)
    @Mapping(target = "memberNickname", ignore = true)
    @Mapping(target = "memberMobile", ignore = true)
    @Mapping(target = "spuName", ignore = true)
    @Mapping(target = "spuImage", ignore = true)
    @Mapping(target = "price", ignore = true)
    @Mapping(target = "browseTime", source = "browseTime", qualifiedByName = "dateToLocalDateTime")
    MallBrowseFootprintInfoVO toInfoVO(MallBrowseFootprint entity);

    @Mapping(target = "memberNo", ignore = true)
    @Mapping(target = "memberNickname", ignore = true)
    @Mapping(target = "memberMobile", ignore = true)
    @Mapping(target = "spuName", ignore = true)
    @Mapping(target = "spuImage", ignore = true)
    @Mapping(target = "price", ignore = true)
    @Mapping(target = "browseTime", source = "browseTime", qualifiedByName = "dateToLocalDateTime")
    MallBrowseFootprintListVO toListSingleVO(MallBrowseFootprint entity);

    @Named("dateToLocalDateTime")
    default LocalDateTime dateToLocalDateTime(Date value) {
        if (value == null) {
            return null;
        }
        return value.toInstant().atZone(ZoneId.of("Asia/Shanghai")).toLocalDateTime();
    }
}
