package com.seer.teach.pay.admin.pay.convert;


import com.alibaba.fastjson2.JSON;
import com.seer.teach.common.utils.AESUtils;
import com.seer.teach.pay.admin.pay.controller.req.AdminPayChannelSaveReq;
import com.seer.teach.pay.admin.pay.controller.req.AdminPayChannelUpdateReq;
import com.seer.teach.pay.admin.pay.controller.resp.PayChannelResp;
import com.seer.teach.pay.entity.PayChannelEntity;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;

import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@Mapper(componentModel = "spring")
public interface PayChannelConvert {

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

    @Mapping(source = "configJson", target = "payInfo", qualifiedByName = "jsonToMap")
    PayChannelResp convertOne(PayChannelEntity payChannelEntity);

    @Mapping(source = "configJson", target = "payInfo", qualifiedByName = "jsonToMap")
    List<PayChannelResp> convertList(List<PayChannelEntity> list);

    PayChannelEntity convertTwo(AdminPayChannelSaveReq payChannelReq);

    PayChannelEntity convertThree(AdminPayChannelUpdateReq payChannelReq);

    @Named("jsonToMap")
    default Map<String, String> jsonToMap(String configJson) {
        if (configJson == null || configJson.trim().isEmpty()) return null;
        try {

            return JSON.parseObject(configJson, Map.class);
        } catch (Exception e) {
            return null;
        }
    }

}
