package org.springblade.face.util.ipaddress;

import java.util.Map;

import com.alibaba.fastjson2.JSONObject;

public class CityInfo {

    private Map<String,String> M;

    public CityInfo(Map<String,String> kv) {
        this.M = kv;
    }

    public String getCountryName() {
        if (this.M.size() > 0) {
            return this.M.get("country_name");
        }
        return null;
    }

    public String getRegionName() {
        if (this.M.size() > 0) {
            return this.M.get("region_name");
        } else {
            return null;
        }
    }

    public String getCityName() {
        if (this.M.size() > 0) {
            return this.M.get("city_name");
        } else {
            return null;
        }
    }

    public AsnInfo[] getAsnInfos() {
        if (this.M.size() > 0) {
            String str = this.M.get("asn_info");
            if (str == null) {
                return null;
            }
            if (!str.startsWith("[")) {
                return null;
            }
            return JSONObject.parseObject(str, AsnInfo[].class);
        }
        return null;
    }

    @Override
    public String toString() {
        JSONObject json = new JSONObject();
        json.put("country_name",this.getCountryName());
        json.put("region_name",this.getRegionName());
        json.put("city_name",this.getCityName());
        return json.toJSONString();
    }
}
