package com.tofly.ghrq_route.module.trouble.domain;

import com.esri.arcgisruntime.data.Feature;
import com.esri.arcgisruntime.geometry.Point;
import com.esri.arcgisruntime.layers.Layer;
import com.mgq.base.utils.string.StringUtil;
import com.tofly.ghrq_route.common.util.Location.LocationUtil;

import java.io.Serializable;
import java.util.Map;

public class DeviceAttributesBean extends AttributesBean implements Serializable {
    public static final String TROUBLE_DEVICE_ATTRIBUTES_BEAN_KEY = "trouble_device_attributes_bean";

    private String altitude;
    private String depth;
    private String name;
    private String x;
    private String y;

    public String getAltitude() {
        return altitude;
    }

    public void setAltitude(String altitude) {
        this.altitude = altitude;
    }

    public String getDepth() {
        return depth;
    }

    public void setDepth(String depth) {
        this.depth = depth;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getX() {
        return x;
    }

    public void setX(String x) {
        this.x = x;
    }

    public String getY() {
        return y;
    }

    public void setY(String y) {
        this.y = y;
    }

    public DeviceAttributesBean(Feature feature) {
        String tableName = feature.getFeatureTable().getTableName();
        this.layerName = tableName;
        Layer layer = feature.getFeatureTable().getLayer();
        if (layer != null)
            this.layerId = layer.getId();
        Point geometry = (Point) feature.getGeometry();
        if (geometry != null) {
            this.geometry = geometry.toJson();
            this.x = LocationUtil.formatLocation(geometry.getX());
            this.y = LocationUtil.formatLocation(geometry.getY());
        }

        Map<String, Object> attributes = feature.getAttributes();
        if (attributes.containsKey("ADDR")) {
            Object object = attributes.get("ADDR");
            String addr = "null";
            if (object != null) {
                addr = object.toString();
            }
            this.address = addr;
        }
        if (attributes.containsKey("Z")) {
            Object object = attributes.get("Z");
            String altitude = "null";
            if (object != null) {
                double value = (double) object;
                altitude = StringUtil.formatDigit(value, 2);
            }
            this.altitude = altitude;
        }
        if (attributes.containsKey("DEPTH")) {
            Object object = attributes.get("DEPTH");
            String depth = "null";
            if (object != null) {
                double value = (double) object;
                depth = StringUtil.formatDigit(value, 2);
            }
            this.depth = depth;
        }
        if (attributes.containsKey("MATERIAL")) {
            Object object = attributes.get("MATERIAL");
            String material = "null";
            if (object != null) {
                material = object.toString();
            }
            this.material = material;
        }
        if (attributes.containsKey("DIAMETER")) {
            Object object = attributes.get("DIAMETER");
            String diameter = "null";
            if (object != null) {
                diameter = object.toString();
            }
            this.pipeDiameter = diameter;
        }
        if (attributes.containsKey("SID")) {
            Object object = attributes.get("SID");
            String sid = "null";
            if (object != null) {
                sid = object.toString();
            }
            this.sid = sid;
        }
        if (attributes.containsKey("SUBTYPE")) {
            Object object = attributes.get("SUBTYPE");
            String subtype = "null";
            if (object != null) {
                subtype = object.toString();
            }
            this.name = subtype;
        }
    }
}