package com.jeequan.jeepay.core.model.ip;

import com.jeequan.jeepay.core.utils.ip.AddressUtils;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * TODO
 * ip解析的地址信息返回结果
 * @author crystal
 * @date 2024/3/21 10:54
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class IpAddressResult implements Serializable {

    public static final byte SUCCESS = 1;

    public static final byte FAIL = -1;

    public static final byte INTERNAL = 0;

    /**
     * 1:获取成功 -1 获取失败 0：内网ip：
     */
    private Byte state;

    private String ip;

    private String pro;

    private String proCode;

    private String city;

    private String cityCode;

    private String region;

    private String regionCode;

    private String addr;

    private String err;

    public IpAddressResult(String ip,Byte state, String addr) {
        this.ip = ip;
        this.state = state;
        this.addr = addr;
    }

    public static IpAddressResult internal(String ip){
        IpAddressResult result = new IpAddressResult(ip,INTERNAL, AddressUtils.LOCATION_TEXT);
        return result;
    }

    public static IpAddressResult fail(String ip,String msg){
        IpAddressResult result = new IpAddressResult(ip,FAIL, msg);
        return result;
    }
}
