package com.jeesharp.business.modules.marketing.memberTenant.convert;

import com.jeesharp.business.modules.marketing.memberTenant.dto.MemberTenantSaveDTO;
import com.jeesharp.business.modules.marketing.memberTenant.entity.MemberTenant;
import com.jeesharp.business.modules.marketing.memberTenant.enums.MemberTenantBindStatusEnum;
import com.jeesharp.business.modules.marketing.memberTenant.enums.MemberTenantJoinSourceEnum;
import com.jeesharp.business.modules.marketing.memberTenant.enums.MemberTenantRoleEnum;
import com.jeesharp.business.modules.marketing.memberTenant.vo.MemberTenantExportVO;
import com.jeesharp.business.modules.marketing.memberTenant.vo.MemberTenantInfoVO;
import com.jeesharp.business.modules.marketing.memberTenant.vo.MemberTenantListVO;
import com.jeesharp.business.modules.marketing.memberTenant.vo.MemberTenantMobileVO;
import com.jeesharp.business.modules.marketing.memberTenant.vo.MemberTenantQueryVO;
import com.jeesharp.framework.common.pojo.convert.BasePojoConvert;
import org.mapstruct.IterableMapping;
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-25
 */
@Mapper
public interface MemberTenantConvert extends BasePojoConvert<MemberTenant, MemberTenantSaveDTO, MemberTenantInfoVO, MemberTenantListVO, MemberTenantQueryVO> {

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

    @Override
    @Named("memberTenantToList")
    @Mapping(target = "bindStatusName", source = "bindStatus", qualifiedByName = "bindStatusToName")
    @Mapping(target = "joinSourceName", source = "joinSource", qualifiedByName = "joinSourceToName")
    @Mapping(target = "memberRoleName", source = "memberRole", qualifiedByName = "memberRoleToName")
    @Mapping(target = "tenantName", ignore = true)
    @Mapping(target = "memberNo", ignore = true)
    @Mapping(target = "memberNickname", ignore = true)
    @Mapping(target = "memberMobile", ignore = true)
    MemberTenantListVO toListSingleVO(MemberTenant entity);

    @Override
    @Named("memberTenantToInfo")
    @Mapping(target = "bindStatusName", source = "bindStatus", qualifiedByName = "bindStatusToName")
    @Mapping(target = "joinSourceName", source = "joinSource", qualifiedByName = "joinSourceToName")
    @Mapping(target = "memberRoleName", source = "memberRole", qualifiedByName = "memberRoleToName")
    @Mapping(target = "tenantName", ignore = true)
    @Mapping(target = "memberNo", ignore = true)
    @Mapping(target = "memberNickname", ignore = true)
    @Mapping(target = "memberMobile", ignore = true)
    MemberTenantInfoVO toInfoVO(MemberTenant entity);

    @Override
    @IterableMapping(qualifiedByName = "memberTenantToList")
    List<MemberTenantListVO> toListVO(List<MemberTenant> list);

    @Override
    @IterableMapping(qualifiedByName = "memberTenantToInfo")
    List<MemberTenantInfoVO> toInfoListVO(List<MemberTenant> list);

    @Mapping(target = "tenantName", ignore = true)
    @Mapping(target = "memberRoleName", source = "memberRole", qualifiedByName = "memberRoleToName")
    MemberTenantMobileVO toMobileVO(MemberTenant entity);

    List<MemberTenantMobileVO> toMobileVOList(List<MemberTenant> list);

    @Mapping(target = "memberNo", ignore = true)
    @Mapping(target = "memberNickname", ignore = true)
    @Mapping(target = "memberMobile", ignore = true)
    @Mapping(target = "tenantName", ignore = true)
    @Mapping(target = "bindStatusName", source = "bindStatus", qualifiedByName = "bindStatusToName")
    @Mapping(target = "joinSourceName", source = "joinSource", qualifiedByName = "joinSourceToName")
    @Mapping(target = "memberRoleName", source = "memberRole", qualifiedByName = "memberRoleToName")
    MemberTenantExportVO toExportVO(MemberTenant entity);

    List<MemberTenantExportVO> toExportVOList(List<MemberTenant> list);

    @Named("bindStatusToName")
    default String bindStatusToName(Integer bindStatus) {
        return MemberTenantBindStatusEnum.getDescByValue(bindStatus);
    }

    @Named("joinSourceToName")
    default String joinSourceToName(String joinSource) {
        return MemberTenantJoinSourceEnum.getDescByValue(joinSource);
    }

    @Named("memberRoleToName")
    default String memberRoleToName(String memberRole) {
        return MemberTenantRoleEnum.getDescByValue(memberRole);
    }
}
