package com.jeesharp.business.modules.pay.paysubmerchantapplyment.convert;

import cn.hutool.json.JSONObject;
import com.jeesharp.business.modules.pay.paysubmerchantapplyment.entity.PaySubMerchantSettlementModify;
import com.jeesharp.business.modules.pay.paysubmerchantapplyment.enums.PaySubMerchantSettlementAccountTypeEnum;
import com.jeesharp.business.modules.pay.paysubmerchantapplyment.enums.PaySubMerchantSettlementModifyAuditEnum;
import com.jeesharp.business.modules.pay.paysubmerchantapplyment.vo.PaySubMerchantSettlementInfoVO;
import com.jeesharp.business.modules.pay.paysubmerchantapplyment.vo.PaySubMerchantSettlementModifyListVO;
import com.jeesharp.business.modules.pay.paysubmerchantapplyment.vo.PaySubMerchantSettlementModifyStatusVO;
import com.jeesharp.business.modules.pay.paysubmerchantapplyment.vo.PaySubMerchantSettlementModifySubmitVO;
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-12
 */
@Mapper
public interface PaySubMerchantSettlementModifyConvert {

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

    @Mapping(target = "accountTypeName", source = "accountType", qualifiedByName = "accountTypeToName")
    @Mapping(target = "auditStatusName", source = "auditStatus", qualifiedByName = "auditStatusToName")
    PaySubMerchantSettlementModifyListVO toListVO(PaySubMerchantSettlementModify entity);

    List<PaySubMerchantSettlementModifyListVO> toListVOList(List<PaySubMerchantSettlementModify> list);

    @Mapping(target = "auditStatusName", source = "auditStatus", qualifiedByName = "auditStatusToName")
    @Mapping(target = "wxResponseJson", ignore = true)
    PaySubMerchantSettlementModifyStatusVO toStatusVO(PaySubMerchantSettlementModify entity);

    @Mapping(target = "auditStatusName", source = "auditStatus", qualifiedByName = "auditStatusToName")
    PaySubMerchantSettlementModifySubmitVO toSubmitVO(PaySubMerchantSettlementModify entity);

    default PaySubMerchantSettlementInfoVO toSettlementInfoVO(JSONObject wx, String wxJson) {
        PaySubMerchantSettlementInfoVO vo = new PaySubMerchantSettlementInfoVO();
        if (wx == null) {
            vo.setWxResponseJson(wxJson);
            return vo;
        }
        vo.setAccountType(wx.getStr("account_type"));
        vo.setAccountTypeName(PaySubMerchantSettlementAccountTypeEnum.getDescByValue(vo.getAccountType()));
        vo.setAccountBank(wx.getStr("account_bank"));
        vo.setBankName(wx.getStr("bank_name"));
        vo.setAccountNumber(wx.getStr("account_number"));
        vo.setAccountName(wx.getStr("account_name"));
        vo.setBankBranchId(wx.getStr("bank_branch_id"));
        vo.setBankAddressCode(wx.getStr("bank_address_code"));
        vo.setWxResponseJson(wxJson);
        return vo;
    }

    @Named("accountTypeToName")
    default String accountTypeToName(String accountType) {
        return PaySubMerchantSettlementAccountTypeEnum.getDescByValue(accountType);
    }

    @Named("auditStatusToName")
    default String auditStatusToName(String auditStatus) {
        return PaySubMerchantSettlementModifyAuditEnum.getDescByValue(auditStatus);
    }
}
