package cn.sikey.mcdisk.service;

import cn.hutool.json.JSONUtil;
import cn.sikey.framework.common.pojo.CommonResult;
import cn.sikey.mcdisk.controller.app.passthrough.vo.PassThroughProxyReqVO;
import cn.sikey.mcdisk.pojo.McdiskResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @Author: nelson
 * @Date: 2025/6/5
 * @Description: 透传代理
 */
@Service
@Slf4j
public class PassThroughProxyServiceImpl extends AbstractMcdiskService implements PassThroughProxyService {

    /**
     * 透传代理
     *
     * @param passThroughProxyReqVO 透传代理
     * @return
     */
    @Override
    public CommonResult passThroughProxy(PassThroughProxyReqVO passThroughProxyReqVO) {
        validateHeaders(passThroughProxyReqVO.getHeaders());
        validateBody(passThroughProxyReqVO.getBody());

        String result = okHttpUtil.handleProxyRequest(passThroughProxyReqVO);
        McdiskResult mcdiskResult = JSONUtil.toBean(result, McdiskResult.class);
        return CommonResult.success(mcdiskResult);
    }
}
