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

import com.esri.arcgisruntime.data.Feature;
import com.esri.arcgisruntime.geometry.ImmutablePart;
import com.esri.arcgisruntime.geometry.Point;
import com.esri.arcgisruntime.geometry.Polyline;
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 PipeAttributesBean extends AttributesBean implements Serializable {
    public static final String TROUBLE_PIPE_ATTRIBUTES_BEAN_KEY = "trouble_pipe_attributes_bean";

    private String endAltitude;
    private String endDepth;
    private String length;
    private String name;
    private String startAltitude;
    private String startDepth;
    private String startX;
    private String startY;
    private String endX;
    private String endY;

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getEndAltitude() {
        return endAltitude;
    }

    public void setEndAltitude(String endAltitude) {
        this.endAltitude = endAltitude;
    }

    public String getEndDepth() {
        return endDepth;
    }

    public void setEndDepth(String endDepth) {
        this.endDepth = endDepth;
    }

    public String getLength() {
        return length;
    }

    public void setLength(String length) {
        this.length = length;
    }

    public String getMaterial() {
        return material;
    }

    public void setMaterial(String material) {
        this.material = material;
    }

    public String getName() {
        return name;
    }

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

    public String getPipeDiameter() {
        return pipeDiameter;
    }

    public void setPipeDiameter(String pipeDiameter) {
        this.pipeDiameter = pipeDiameter;
    }

    public String getSid() {
        return sid;
    }

    public void setSid(String sid) {
        this.sid = sid;
    }

    public String getStartAltitude() {
        return startAltitude;
    }

    public void setStartAltitude(String startAltitude) {
        this.startAltitude = startAltitude;
    }

    public String getStartDepth() {
        return startDepth;
    }

    public void setStartDepth(String startDepth) {
        this.startDepth = startDepth;
    }

    public String getStartX() {
        return startX;
    }

    public void setStartX(String startX) {
        this.startX = startX;
    }

    public String getStartY() {
        return startY;
    }

    public void setStartY(String startY) {
        this.startY = startY;
    }

    public String getEndX() {
        return endX;
    }

    public void setEndX(String endX) {
        this.endX = endX;
    }

    public String getEndY() {
        return endY;
    }

    public void setEndY(String endY) {
        this.endY = endY;
    }

    public String getGeometry() {
        return geometry;
    }

    public void setGeometry(String geometry) {
        this.geometry = geometry;
    }

    public String getLayerId() {
        return layerId;
    }

    public void setLayerId(String layerId) {
        this.layerId = layerId;
    }

    public String getLayerName() {
        return layerName;
    }

    public void setLayerName(String layerName) {
        this.layerName = layerName;
    }

    public PipeAttributesBean(Feature feature) {
        String tableName = feature.getFeatureTable().getTableName();
        this.layerName = tableName;
        Layer layer = feature.getFeatureTable().getLayer();
        if (layer != null)
            this.layerId = layer.getId();
        Polyline geometry = (Polyline) feature.getGeometry();
        if (geometry != null) {
            this.geometry = geometry.toJson();
            if (geometry.getParts().size() > 0) {
                ImmutablePart part = geometry.getParts().get(0);
                if (part != null) {
                    Point point = part.getStartPoint();
                    if (point != null) {
                        this.startX = LocationUtil.formatLocation(point.getX());
                        this.startY = LocationUtil.formatLocation(point.getY());
                    }
                    Point lastPoint = part.getEndPoint();
                    if (lastPoint != null) {
                        this.endX = LocationUtil.formatLocation(lastPoint.getX());
                        this.endY = LocationUtil.formatLocation(lastPoint.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("END_HEIGHT")) {
            Object object = attributes.get("END_HEIGHT");
            String altitude = "null";
            if (object != null) {
                double value = (double) object;
                altitude = StringUtil.formatDigit(value, 2);
            }
            this.endAltitude = altitude;
        }
        if (attributes.containsKey("END_DEPTH")) {
            Object object = attributes.get("END_DEPTH");
            String depth = "null";
            if (object != null) {
                double value = (double) object;
                depth = StringUtil.formatDigit(value, 2);
            }
            this.endDepth = depth;
        }
        if (attributes.containsKey("PIPELENGTH")) {
            Object object = attributes.get("PIPELENGTH");
            String length = "null";
            if (object != null) {
                double value = (double) object;
                length = StringUtil.formatDigit(value, 2);
            }
            this.length = length;
        }
        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;
        }
        if (attributes.containsKey("START_HEIGHT")) {
            Object object = attributes.get("START_HEIGHT");
            String start_height = "null";
            if (object != null) {
                double value = (double) object;
                start_height = StringUtil.formatDigit(value, 2);
            }
            this.startAltitude = start_height;
        }
        if (attributes.containsKey("START_DEPTH")) {
            Object object = attributes.get("START_DEPTH");
            String start_depth = "null";
            if (object != null) {
                double value = (double) object;
                start_depth = StringUtil.formatDigit(value, 2);
            }
            this.startDepth = start_depth;
        }
    }
}