package com.ecep.contract.cloud.rk;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Getter;
import lombok.Setter;

import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URI;

public class BlackListUpdateContext {


    @Setter
    @Getter
    private ObjectMapper objectMapper;
    private Proxy.Type proxyType;
    @Getter
    private Proxy socksProxy;
    @Setter
    @Getter
    private String url;
    @Getter
    private long elapse = 1440;


    public void setProxy(String proxy) {
        if (proxy != null) {
            URI proxyUri = URI.create(proxy);
            proxyType = Proxy.Type.valueOf(proxyUri.getScheme().toUpperCase());
            socksProxy = new Proxy(
                    proxyType,
                    new InetSocketAddress(proxyUri.getHost(), proxyUri.getPort())
            );
        }
    }

    public void setElapse(String value) {
        elapse = Long.parseLong(value);
    }

}
