package com.ema.common.domain.vo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * IP信息VO
 */
@ApiModel(description = "IPVo")
@Data
@NoArgsConstructor
public class IPVo implements Serializable {

    @ApiModelProperty(value = "IP")
    private String ip;

    @ApiModelProperty(value = "国家")
    private String country;

    @ApiModelProperty(value = "省份")
    private String province;

    @ApiModelProperty(value = "城市")
    private String city;

    @ApiModelProperty(value = "提供服务公司")
    private String company;

    public IPVo(String ipAddr, String region) {
        ip = ipAddr;
        String[] regArr = region.split("\\|");
        country = "0".equals(regArr[0]) ? "未知" : regArr[0];
        province = "0".equals(regArr[2]) ? "未知" : regArr[2];
        city = "0".equals(regArr[3]) ? "未知" : regArr[3];
        company = "0".equals(regArr[4]) ? "未知" : regArr[4];
    }
}
