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

import com.esri.arcgisruntime.geometry.Point;
import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes;
import com.google.gson.FieldNamingStrategy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import com.tofly.ghrq_route.module.OfflineWork.domain.List_String_Converter;
import com.tofly.ghrq_route.module.plan.domain.OfflinePathBean;
import com.tofly.ghrq_route.module.uploadFile.domain.FileBean;

import org.greenrobot.greendao.annotation.Convert;
import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Index;
import org.greenrobot.greendao.annotation.Transient;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.List;
import java.util.UUID;

/**
 * Created by Amu on 2017/3/23.
 */
@Entity(nameInDb = "DB_POINT_REPAIR", indexes = {@Index(value = "point_id DESC,  plan_id DESC", unique = true)})
@SuppressWarnings("serial")
public class PlanPointRepair implements Serializable {

    /**
     * id : 518C789CC9F84F438F7751294EFBE6CB
     * point_id : 2808116CF88C49F0BFAEDE831AEB462A
     * lat : 129.580424929803
     * lng : 106.515010593366
     * point_name : 设备3
     * closing_pressure :
     * create_time : 2017-06-07 17:12:09
     * cutting_pressure :
     * is_in_place : null
     * lat : 29.569699874383126
     * lng : 106.51401584359625
     * leak_detect :
     * notes :
     * operating_pressure :
     * point_id : B24301
     * point_name :
     * switch_flexible :
     * before :
     * after :
     * qt_pic :
     */

    public static final String POINT_REPAIR_BEAN_KEY = "point_repair_bean";
    public static final String POINT_REPAIR_UPDATE_KEY = "point_repair_is_update";
    public static final String POINT_REPAIR_EDITABLE_KEY = "point_repair_is_editable";
    public static final String POINT_REPAIR_REMOVABLE_KEY = "point_repair_is_removable";
    public static final String POINT_REPAIR_IS_NEW_KEY = "point_repair_is_new";
    public static final String POINT_REPAIR_IS_LOCAL_KEY = "point_repair_is_local";

    @Id(autoincrement = true)
    @Expose(serialize = false, deserialize = false)
    public Long id;
    private String temp_id;
    @SerializedName(value = "planTempPointId")
    private String point_id;         //设备类型唯一编码[必填]
    @SerializedName(value = "x")
    private double lng;             //设备定位经度[必填]
    @SerializedName(value = "y")
    private double lat;             //设备定位纬度[必填]
    private String address;         //设备定位地址[选填]
    private String code;
    @SerializedName(value = "createDate")
    private String create_time;
    private int is_in_place;
    @SerializedName(value = "repairContent")
    private String notes;
    private String point_name;
    private String plan_point_id;
    @SerializedName(value = "childPlanId")
    private String plan_id;
    private String deviceUser;
    private String deviceUserDeptId;
    private String checkBeginDate;
    private String checkEndDate;
    @SerializedName(value = "region")
    private String checkRegion;
    @Convert(columnType = String.class, converter = List_String_Converter.class)
    private List<String> content;
    @Convert(columnType = String.class, converter = AdjustRepairContent.List_RepairContent_Converter.class)
    private List<AdjustRepairContent> contents;
    @Transient
    private List<FileBean> files;
    private int state;
    private boolean isUpdating = false;

    public PlanPointRepair(OfflinePathBean planPoint, Point Location){
        String repairId = UUID.randomUUID().toString();
        this.temp_id = repairId;
        this.address = "";
        if (planPoint != null){
            this.point_id = planPoint.getPoint_id();
            this.plan_point_id = planPoint.getTemp_id();
            this.plan_id = planPoint.getPlan_id();
        }
        if (Location != null){
            this.lng = Location.getX();
            this.lat = Location.getY();
        }
    }

    @Generated(hash = 1745932333)
    public PlanPointRepair(Long id, String temp_id, String point_id, double lng, double lat, String address,
            String code, String create_time, int is_in_place, String notes, String point_name,
            String plan_point_id, String plan_id, String deviceUser, String deviceUserDeptId,
            String checkBeginDate, String checkEndDate, String checkRegion, List<String> content,
            List<AdjustRepairContent> contents, int state, boolean isUpdating) {
        this.id = id;
        this.temp_id = temp_id;
        this.point_id = point_id;
        this.lng = lng;
        this.lat = lat;
        this.address = address;
        this.code = code;
        this.create_time = create_time;
        this.is_in_place = is_in_place;
        this.notes = notes;
        this.point_name = point_name;
        this.plan_point_id = plan_point_id;
        this.plan_id = plan_id;
        this.deviceUser = deviceUser;
        this.deviceUserDeptId = deviceUserDeptId;
        this.checkBeginDate = checkBeginDate;
        this.checkEndDate = checkEndDate;
        this.checkRegion = checkRegion;
        this.content = content;
        this.contents = contents;
        this.state = state;
        this.isUpdating = isUpdating;
    }

    @Generated(hash = 2062381474)
    public PlanPointRepair() {
    }

    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getTemp_id() {
        return temp_id;
    }

    public void setTemp_id(String temp_id) {
        this.temp_id = temp_id;
    }

    public String getPoint_id() {
        return this.point_id;
    }

    public void setPoint_id(String point_id) {
        this.point_id = point_id;
    }

    public double getLng() {
        return this.lng;
    }

    public void setLng(double lng) {
        this.lng = lng;
    }

    public double getLat() {
        return this.lat;
    }

    public void setLat(double lat) {
        this.lat = lat;
    }

    public String getAddress() {
        return this.address;
    }

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


    public String getCode() {
        return this.code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getCreate_time() {
        return this.create_time;
    }

    public void setCreate_time(String create_time) {
        this.create_time = create_time;
    }

    public int getIs_in_place() {
        return this.is_in_place;
    }

    public void setIs_in_place(int is_in_place) {
        this.is_in_place = is_in_place;
    }

    public String getNotes() {
        return this.notes;
    }

    public void setNotes(String notes) {
        this.notes = notes;
    }

    public String getPoint_name() {
        return this.point_name;
    }

    public void setPoint_name(String point_name) {
        this.point_name = point_name;
    }

    public String getPlan_point_id() {
        return this.plan_point_id;
    }

    public void setPlan_point_id(String plan_point_id) {
        this.plan_point_id = plan_point_id;
    }

    public String getPlan_id() {
        return this.plan_id;
    }

    public void setPlan_id(String plan_id) {
        this.plan_id = plan_id;
    }

    public int getState() {
        return this.state;
    }

    public void setState(int state) {
        this.state = state;
    }

    public String getDeviceUser() {
        return this.deviceUser;
    }

    public void setDeviceUser(String deviceUser) {
        this.deviceUser = deviceUser;
    }

    public List<String> getContent() {
        return this.content;
    }

    public void setContent(List<String> content) {
        this.content = content;
    }

    public String getCheckBeginDate() {
        return this.checkBeginDate;
    }

    public void setCheckBeginDate(String checkBeginDate) {
        this.checkBeginDate = checkBeginDate;
    }

    public String getCheckEndDate() {
        return this.checkEndDate;
    }

    public void setCheckEndDate(String checkEndDate) {
        this.checkEndDate = checkEndDate;
    }

    public String getCheckRegion() {
        return this.checkRegion;
    }

    public void setCheckRegion(String checkRegion) {
        this.checkRegion = checkRegion;
    }

    public boolean isUpdating() {
        return this.isUpdating;
    }

    public void setIsUpdating(boolean isUpdating) {
        this.isUpdating = isUpdating;
    }

    public boolean getIsUpdating() {
        return this.isUpdating;
    }


    public String getDeviceUserDeptId() {
        return this.deviceUserDeptId;
    }


    public void setDeviceUserDeptId(String deviceUserDeptId) {
        this.deviceUserDeptId = deviceUserDeptId;
    }

    public List<FileBean> getFiles() {
        return files;
    }

    public void setFiles(List<FileBean> files) {
        this.files = files;
    }

    public List<AdjustRepairContent> getContents() {
        return this.contents;
    }

    public void setContents(List<AdjustRepairContent> contents) {
        this.contents = contents;
    }

    public static Gson getGsonAdjustContentNaming() {
        return new GsonBuilder()
                .setExclusionStrategies(new AdjustContentExclusionStrategy())
                .setFieldNamingStrategy(new AdjustContentFieldNamingStrategy())
                .create();
    }

    private static class AdjustContentExclusionStrategy implements ExclusionStrategy {
        @Override
        public boolean shouldSkipField(FieldAttributes fieldAttributes) {
            return "content".equals(fieldAttributes.getName());
        }

        @Override
        public boolean shouldSkipClass(Class<?> aClass) {
            return false;
        }
    }

    private static class AdjustContentFieldNamingStrategy implements FieldNamingStrategy {
        public String translateName(Field f) {
            if ("contents".equals(f.getName())) {
                return "content";
            }
            return f.getName();
        }
    }

}
