package net.northking.cctp.element.internal.protocol.http;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import java.net.URL;

/**
 * HttpClientKey
 *
 * @author fengxiang.zhang
 * @date 2022/4/14
 * @since 1.0
 */
public class HttpClientKey {

    private String target;
    private RequestParam.Proxy proxy;

    public HttpClientKey() {
    }

    public HttpClientKey(URL url, RequestParam.Proxy proxy) {
        this.target = url.getProtocol() + "://" + url.getAuthority();
        this.proxy = proxy;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;

        if (o == null || getClass() != o.getClass()) return false;
        HttpClientKey that = (HttpClientKey) o;
        return new EqualsBuilder()
                .append(target, that.target)
                .append(proxy, that.proxy)
                .isEquals();
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder(17, 37)
                .append(target)
                .append(proxy)
                .toHashCode();
    }
}
