package com.apobates.forum.event.utils;

/**
 * IP地址匹配的结果
 *
 * @author xiaofanku
 * @since 20200530
 */
public final class IpMatchResult {
    private final String ipAddr;
    //供应商:联通|电信
    private final String isp;
    //地域:省
    private final String province;
    //地域:市
    private final String city;
    //地域:区
    private final String district;
    
    public IpMatchResult(String ipAddr, String isp, String province, String city, String district) {
        this.ipAddr = ipAddr;
        this.isp = isp;
        this.province = province;
        this.city = city;
        this.district = district;
    }
    
    /**
     * 返回ISP供应商,例:联通
     *
     * @return
     */
    public String getIsp() {
        return isp;
    }
    
    /**
     * 返回省份,例:山东省
     *
     * @return
     */
    public String getProvince() {
        return province;
    }
    
    /**
     * 返回市,例:烟台市
     *
     * @return
     */
    public String getCity() {
        return city;
    }
    
    /**
     * 返回区或县
     *
     * @return
     */
    public String getDistrict() {
        return district;
    }
    
    public String getIpAddr() {
        return ipAddr;
    }
    
    public static IpMatchResult empty(String ipAddr) {
        return new IpMatchResult(ipAddr, IpMatcher.MARK, IpMatcher.MARK, IpMatcher.MARK, IpMatcher.MARK);
    }
    
    @Override
    public String toString() {
        return String.format("{\"IP\":\"%s\", \"ISP供应商\":\"%s\", \"省\":\"%s\", \"市\": \"%s\"}", getIpAddr(), getIsp(), getProvince(), getCity());
    }
}