package com.jeesharp.business.modules.finance.profitsharing.convert;

import com.jeesharp.business.modules.finance.profitsharing.dto.ProfitSharingOrderSaveDTO;
import com.jeesharp.business.modules.finance.profitsharing.entity.ProfitSharingOrder;
import com.jeesharp.business.modules.finance.profitsharing.entity.ProfitSharingReceiver;
import com.jeesharp.business.modules.finance.profitsharing.enums.ProfitSharingReceiverResultEnum;
import com.jeesharp.business.modules.finance.profitsharing.enums.ProfitSharingStatusEnum;
import com.jeesharp.business.modules.finance.profitsharing.vo.ProfitSharingOrderInfoVO;
import com.jeesharp.business.modules.finance.profitsharing.vo.ProfitSharingOrderListVO;
import com.jeesharp.business.modules.finance.profitsharing.vo.ProfitSharingOrderQueryVO;
import com.jeesharp.business.modules.finance.profitsharing.vo.ProfitSharingReceiverListVO;
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 转换器，继承 {@code BasePojoConvert} 并补充状态展示字段映射。
 *
 * @author jeesharp
 * @since 2026-06-11
 */
@Mapper
public interface ProfitSharingOrderConvert extends BasePojoConvert<ProfitSharingOrder, ProfitSharingOrderSaveDTO,
        ProfitSharingOrderInfoVO, ProfitSharingOrderListVO, ProfitSharingOrderQueryVO> {

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

    @Mapping(target = "statusName", source = "status", qualifiedByName = "statusToName")
    @Mapping(target = "orderNo", ignore = true)
    @Mapping(target = "batchNo", ignore = true)
    @Mapping(target = "receivers", ignore = true)
    @Override
    ProfitSharingOrderInfoVO toInfoVO(ProfitSharingOrder entity);

    @Mapping(target = "statusName", source = "status", qualifiedByName = "statusToName")
    @Mapping(target = "orderNo", ignore = true)
    @Mapping(target = "batchNo", ignore = true)
    ProfitSharingOrderListVO toListSingleVO(ProfitSharingOrder entity);

    @Mapping(target = "resultName", source = "result", qualifiedByName = "receiverResultToName")
    ProfitSharingReceiverListVO toReceiverListVO(ProfitSharingReceiver entity);

    List<ProfitSharingReceiverListVO> toReceiverListVOList(List<ProfitSharingReceiver> list);

    @Named("statusToName")
    default String statusToName(String status) {
        return ProfitSharingStatusEnum.getDescByValue(status);
    }

    @Named("receiverResultToName")
    default String receiverResultToName(String result) {
        return ProfitSharingReceiverResultEnum.getDescByValue(result);
    }
}
