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

import com.jeesharp.business.modules.finance.merchantreceivable.enums.MerchantReceivableEntryTypeEnum;
import com.jeesharp.business.modules.finance.merchantsettlement.entity.MerchantSettlementBill;
import com.jeesharp.business.modules.finance.merchantsettlement.entity.MerchantSettlementBillLine;
import com.jeesharp.business.modules.finance.merchantsettlement.entity.MerchantSettlementPayout;
import com.jeesharp.business.modules.finance.merchantsettlement.enums.MerchantSettlementBillStatusEnum;
import com.jeesharp.business.modules.finance.merchantsettlement.enums.MerchantSettlementPayoutMethodEnum;
import com.jeesharp.business.modules.finance.merchantsettlement.vo.MerchantSettlementBillInfoVO;
import com.jeesharp.business.modules.finance.merchantsettlement.vo.MerchantSettlementBillLineListVO;
import com.jeesharp.business.modules.finance.merchantsettlement.vo.MerchantSettlementBillListVO;
import com.jeesharp.business.modules.finance.merchantsettlement.vo.MerchantSettlementBillQueryVO;
import com.jeesharp.business.modules.finance.merchantsettlement.vo.MerchantSettlementPayoutListVO;
import com.jeesharp.framework.common.pojo.convert.BasePojoConvert;
import com.jeesharp.business.modules.finance.merchantsettlement.dto.MerchantSettlementBillSaveDTO;
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-29
 */
@Mapper
public interface MerchantSettlementBillConvert extends BasePojoConvert<MerchantSettlementBill, MerchantSettlementBillSaveDTO,
        MerchantSettlementBillInfoVO, MerchantSettlementBillListVO, MerchantSettlementBillQueryVO> {

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

    @Mapping(target = "statusName", source = "status", qualifiedByName = "statusToName")
    @Override
    MerchantSettlementBillInfoVO toInfoVO(MerchantSettlementBill entity);

    @Mapping(target = "statusName", source = "status", qualifiedByName = "statusToName")
    MerchantSettlementBillListVO toListSingleVO(MerchantSettlementBill entity);

    @Mapping(target = "payoutMethodName", source = "payoutMethod", qualifiedByName = "payoutMethodToName")
    MerchantSettlementPayoutListVO toPayoutListVO(MerchantSettlementPayout entity);

    List<MerchantSettlementPayoutListVO> toPayoutListVOList(List<MerchantSettlementPayout> list);

    @Mapping(target = "entryTypeName", source = "entryType", qualifiedByName = "entryTypeToName")
    MerchantSettlementBillLineListVO toLineListVO(MerchantSettlementBillLine entity);

    List<MerchantSettlementBillLineListVO> toLineListVOList(List<MerchantSettlementBillLine> list);

    @Named("entryTypeToName")
    default String entryTypeToName(String entryType) {
        return MerchantReceivableEntryTypeEnum.getDescByValue(entryType);
    }

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

    @Named("payoutMethodToName")
    default String payoutMethodToName(String payoutMethod) {
        return MerchantSettlementPayoutMethodEnum.getDescByValue(payoutMethod);
    }
}
