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

import com.jeesharp.business.modules.member.dto.MemberPointsLogSaveDTO;
import com.jeesharp.business.modules.member.entity.MemberPointsLog;
import com.jeesharp.business.modules.member.enums.MemberPointsBizTypeEnum;
import com.jeesharp.business.modules.member.enums.MemberPointsTypeEnum;
import com.jeesharp.business.modules.member.vo.MemberPointsLogExportVO;
import com.jeesharp.business.modules.member.vo.MemberPointsLogInfoVO;
import com.jeesharp.business.modules.member.vo.MemberPointsLogListVO;
import com.jeesharp.business.modules.member.vo.MemberPointsLogQueryVO;
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.util.List;

/**
 * 会员积分流水 MapStruct 转换器。
 *
 * @author jeesharp
 * @since 2026-06-24
 */
@Mapper
public interface MemberPointsLogConvert extends BasePojoConvert<
        MemberPointsLog, MemberPointsLogSaveDTO, MemberPointsLogInfoVO, MemberPointsLogListVO, MemberPointsLogQueryVO> {

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

    @Override
    @Mapping(target = "pointsTypeName", source = "pointsType", qualifiedByName = "pointsTypeToName")
    @Mapping(target = "bizTypeName", source = "bizType", qualifiedByName = "bizTypeToName")
    @Mapping(target = "memberNo", ignore = true)
    @Mapping(target = "memberNickname", ignore = true)
    @Mapping(target = "memberMobile", ignore = true)
    MemberPointsLogInfoVO toInfoVO(MemberPointsLog entity);

    @Override
    @Mapping(target = "pointsTypeName", source = "pointsType", qualifiedByName = "pointsTypeToName")
    @Mapping(target = "bizTypeName", source = "bizType", qualifiedByName = "bizTypeToName")
    @Mapping(target = "memberNo", ignore = true)
    @Mapping(target = "memberNickname", ignore = true)
    @Mapping(target = "memberMobile", ignore = true)
    MemberPointsLogListVO toListSingleVO(MemberPointsLog entity);

    @Mapping(target = "pointsTypeName", source = "pointsType", qualifiedByName = "pointsTypeToName")
    @Mapping(target = "bizTypeName", source = "bizType", qualifiedByName = "bizTypeToName")
    @Mapping(target = "memberNo", ignore = true)
    @Mapping(target = "memberNickname", ignore = true)
    @Mapping(target = "memberMobile", ignore = true)
    MemberPointsLogExportVO toExportVO(MemberPointsLog entity);

    List<MemberPointsLogExportVO> toExportVOList(List<MemberPointsLog> list);

    @Named("pointsTypeToName")
    default String pointsTypeToName(Integer pointsType) {
        return MemberPointsTypeEnum.getDescByValue(pointsType);
    }

    @Named("bizTypeToName")
    default String bizTypeToName(String bizType) {
        return MemberPointsBizTypeEnum.getDescByCode(bizType);
    }
}
