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

import com.jeesharp.business.modules.member.dto.MemberPointsRuleSaveDTO;
import com.jeesharp.business.modules.member.entity.MemberPointsRule;
import com.jeesharp.business.modules.member.enums.MemberPointsCalcTypeEnum;
import com.jeesharp.business.modules.member.enums.MemberPointsSceneEnum;
import com.jeesharp.business.modules.member.vo.MemberPointsRuleInfoVO;
import com.jeesharp.business.modules.member.vo.MemberPointsRuleListVO;
import com.jeesharp.business.modules.member.vo.MemberPointsRuleQueryVO;
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;

/**
 * 积分规则 MapStruct 转换器。
 *
 * @author jeesharp
 * @since 2026-06-23
 */
@Mapper
public interface MemberPointsRuleConvert extends BasePojoConvert<
        MemberPointsRule, MemberPointsRuleSaveDTO, MemberPointsRuleInfoVO, MemberPointsRuleListVO, MemberPointsRuleQueryVO> {

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

    @Mapping(target = "sceneName", source = "sceneCode", qualifiedByName = "sceneToName")
    @Mapping(target = "calcTypeName", source = "calcType", qualifiedByName = "calcTypeToName")
    @Mapping(target = "statusName", source = "status", qualifiedByName = "statusToName")
    @Mapping(target = "levelItems", ignore = true)
    MemberPointsRuleInfoVO toInfoVO(MemberPointsRule entity);

    @Mapping(target = "sceneName", source = "sceneCode", qualifiedByName = "sceneToName")
    @Mapping(target = "calcTypeName", source = "calcType", qualifiedByName = "calcTypeToName")
    @Mapping(target = "statusName", source = "status", qualifiedByName = "statusToName")
    MemberPointsRuleListVO toListSingleVO(MemberPointsRule entity);

    @Named("sceneToName")
    default String sceneToName(String sceneCode) {
        return MemberPointsSceneEnum.getDescByCode(sceneCode);
    }

    @Named("calcTypeToName")
    default String calcTypeToName(String calcType) {
        MemberPointsCalcTypeEnum item = MemberPointsCalcTypeEnum.fromCode(calcType);
        return item != null ? item.getDesc() : "";
    }

    @Named("statusToName")
    default String statusToName(Integer status) {
        if (status == null) {
            return "";
        }
        return status == 1 ? "启用" : "禁用";
    }
}
