package org.wcs.helper;

import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
@RequiredArgsConstructor
public class HttpResponseHelper {

    private final StringRedisTemplate stringRedisTemplate;

    private static final String RECORD_ID_KEY = "WCS:HTTP:RESPONSE";

    /**
     * 获取响应结果
     *
     * @param recordId 记录ID
     * @return 响应结果
     */
    public String getResponse(String recordId) {
        return stringRedisTemplate.opsForValue().get(RECORD_ID_KEY + ":" + recordId);
    }

    /**
     * 设置响应结果
     *
     * @param recordId 响应结果
     * @param response 响应结果
     * @param timeout  超时时间
     */
    public void setResponse(String recordId, String response, long timeout) {
        stringRedisTemplate.opsForValue().set(RECORD_ID_KEY + ":" + recordId, response, timeout, TimeUnit.SECONDS);
    }


}
