package cn.edu.whu.boot.common.domain;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * CommonConstant 类主要定义固定常量字符串!
 *
 * @author Zhou Chao
 */
@Component
public class CommonConstant {

    public static final String FAILED = "failed";
    public static final String SUCCEED = "succeed";

    /**
     * 在 TaskController 类中的创建任务接口中，传入的 String configString 是以 Json 形式传输的!
     * Json 形式如下：
     * {
     * "name":"",
     * "key":"",
     * "taskUploadTime":"",
     * "introduction":"",
     * "id":"",
     * "isAllocationOptional":""
     * "config":{...}
     * }
     * 上面 key 分别对应着任务名称、关键字、任务上传时间、任务备注、当前操作用户id、具体的 xml 文件配置!!!
     * 其中 "config":{...} 中的 Json 内容参考下面解释!!!
     * 另外因为其他地方也会用到 name 和 key 字符串，所以这里并没有添加特定的 TASK_ 前缀
     */
    public static final String NAME = "name";
    public static final String KEY = "key";
    public static final String TASK_INTRODUCTION = "introduction";
    public static final String TASK_UPLOADTIME = "taskUploadTime";
    public static final String TASK_USER_ID = "id";
    public static final String TASK_IS_ALLOCATION_OPTIONAL = "isAllocationOptional";
    public static final String TASK_XML_CONFIG = "config";

    /**
     * "config":{...} 中的 Json 内容如下所示，看这部分注释时同时观察 XML 文件更容易理解!!!
     * {
     * "meta":{
     * "drawtool":[{ "name":"location" },  ...    ],
     * "position":[{ "name":"gps" },   ...   ],
     * "basemap":[{ "name":"天地图底图", "index":"0", "subType":"VEC_C", "type":"tianditu",
     * "group":"vector", "url":""},   ...   ]
     * },
     * "tables":[{
     * "name":"测试1", "key":"test",
     * "fields":[{ "index":"", "name":"", "type":"", "selector":[], "select":"" ,"mode":"" ,
     * "key":"ID" ,"parentID":"", "dbType":"integer", "resultType":"", "geometry":"",
     * "required":"", "identity":true, "uploadName":"", "autoDate":"", "show":"",
     * "enable":"", "script":"", "associate":"", "collection":"", "autoIncrement":true
     * },   ...   ]
     * },   ...   ]
     * }
     */
    public static final String TAG_META = "meta";
    public static final String TAG_TABLES = "tables";
    public static final String TAG_DRAWTOOL = "drawtool";
    public static final String TAG_DRAWTOOL_GROUP = "group";
    public static final String TAG_POSITIOON = "position";
    public static final String TAG_BASEMAP = "basemap";
    public static final String TAG_TYPE = "type";
    public static final String TAG_LAYER = "layer";
    public static final String TAG_TABLE = "table";
    public static final String TAG_FIELD = "field";
    public static final String TABLES_FIELDS = "fields";
    public static final String FIELD_KEY = "key";
    public static final String FIELD_NAME = "name";
    public static final String FIELD_TYPE = "type";
    public static final String FIELD_SELECTOR = "selector";
    public static final String FIELD_INDEX = "index";
    public static final String FIELD_SELECT = "select";
    public static final String FIELD_MODE = "mode";
    public static final String FIELD_PARENT_ID = "parentID";
    public static final String FIELD_DB_TYPE = "dbType";
    public static final String FIELD_RESULT_TYPE = "resultType";
    public static final String FIELD_GEOMETRY = "geometry";
    public static final String FIELD_REQUIRED = "required";
    public static final String FIELD_IDENTITY = "identity";
    public static final String FIELD_UPLOAD_NAME = "uploadName";
    public static final String FIELD_AUTO_DATE = "autoDate";
    public static final String FIELD_SHOW = "show";
    public static final String FIELD_ENABLE = "enable";
    public static final String FIELD_SCRIPT = "script";
    public static final String FIELD_ASSOCIATE = "associate";
    public static final String FIELD_COLLECTION = "collection";
    public static final String FIELD_AUTO_INCREMENT = "autoIncrement";

    /**
     * 每个表中固定会有的字段!!! 所以这些字段名不能被使用!
     * version 版本号
     * collector 采集人
     * reviewer 审核人
     * create_time 创建时间
     * update_time 更新时间
     * status 数据状态 ：  -1  审核未通过
     * 0  已分配，未审核(经过韦瀚植的自动分配) ；
     * 1  已采集，未审核
     * 2  已审核
     * reason 数据未通过审核原因
     * <p>
     * 另外 geometry 和 date 虽然不是固定字段，但是这两个字符串比较特殊，也不能被使用!
     * filepath 是通过文件向表中导入数据的作为多媒体文件标志的固定列名!!!
     */
    public static final String FIX_FIELD_VERSION = "version";
    public static final String FIX_FIELD_COLLECTOR = "collector";
    public static final String FIX_FIELD_REVIEWER = "reviewer";
    public static final String FIX_FIELD_CREATE_TIME = "create_time";
    public static final String FIX_FIELD_UPDATE_TIME = "update_time";
    public static final String FIX_FIELD_STATUS = "status";
    public static final String FIX_FIELD_REASON = "reason";
    public static final String GEOMETRY = "geometry";
    public static final String FILE_PATH = "filepath";
    public static final Set<String> FIX_FIELD_SET = new HashSet<String>() {
        private static final long serialVersionUID = 1263688440065455203L;

        {
            add(FIX_FIELD_VERSION);
            add(FIX_FIELD_COLLECTOR);
            add(FIX_FIELD_REVIEWER);
            add(FIX_FIELD_CREATE_TIME);
            add(FIX_FIELD_UPDATE_TIME);
            add(FIX_FIELD_STATUS);
            add(FIX_FIELD_REASON);
            add(GEOMETRY);
            add(FILE_PATH);
            add(DATE);
            add("");
        }
    };

    /**
     * DATE_FORMAT_STRING 是正常时间的字符串格式
     */
    public static final String DATE_FORMAT_STRING = "yyyy-MM-dd HH:mm:ss";
    public static final String FILE_DATE_FORMAT_STRING = "yyyy-MM-dd HH-mm-ss";

    /**
     * 网页端编辑任务中几个可选择的 DBType 字符串
     */
    public static final String INTEGER = "integer";
    public static final String STRING = "string";
    public static final String TEXT = "text";
    public static final String BLOB = "blob";
    public static final String DATE = "date";
    public static final String LONG = "long";
    public static final String DOUBLE = "double";

    /**
     * 安卓端控件类型
     */
    public static final String PHOTO = "photo";
    public static final String CAMERA = "camera";

    /**
     * 数据库多媒体和历史表后缀字符串，以及固定轨迹和草图表名
     */
    public static final String MEDIA_SUFFIX = "_media";
    public static final String HISTORY_SUFFIX = "_history";
    public static final String MEDIA_HISTORY_SUFFIX = "_media_history";
    public static final String ROUTE_LINE = "route_line";
    public static final String DRAFT = "draft";

    /**
     * 移动端上传的空间数据涉及到的字符串
     */
    public static final String X = "x";
    public static final String Y = "y";
    public static final String PATHS = "paths";
    public static final String RINGS = "rings";

    /**
     * 定义前端要求的Feature类中涉及的常量字符串
     */
    public static final String MULTIPOLYGON = "MultiPolygon";
    public static final String POINT = "Point";
    public static final String LINESTRING = "LineString";
    public static final String POLYGON = "Polygon";
    public static final String FEATURE = "Feature";

    /**
     * 访问图片及视频文件的固定ip前缀字符串
     */
    public static final String GET_PICTURE_PREFIX = "/get/getPicture/";
    public static final String GET_VIDEO_PREFIX = "/get/getVideo/";

    /**
     * xml文件名前缀
     */
    public static final String XML_FILENAME_PREFIX = "Xml_";

    /**
     * 定义两个固定字符串表示Android 和 Browser 端
     */
    public static final String ANDROID = "android";
    public static final String BROWSER = "browser";

    /**
     * 安卓端传来的 ShapeString 中"spatialReference"相关固定个字符串
     */
    public static final String SPATIAL_REFERENCE = "spatialReference";
    public static final Map<String, Integer> SPATIAL_REFERENCE_VALUE = new HashMap<String, Integer>() {
        private static final long serialVersionUID = 6477119511765851104L;

        {
            put("wkid", 4490);
        }
    };

    /**
     * 静态资源根目录
     */
    public static String STATIC_RESOURCE_ROOT;

    @Value("${static.file.path}")
    public void setStaticResourceRoot(String staticResourceRoot) {
        CommonConstant.STATIC_RESOURCE_ROOT = staticResourceRoot;
    }

    /**
     * 多媒体文件的根目录
     */
    public static String MEDIA_ROOT;

    @Value("${MediaPath}")
    public void setMediaRoot(String mediaRoot) {
        CommonConstant.MEDIA_ROOT = mediaRoot;
    }

    /**
     * 中间文件路径,多媒体文件路径,历史多媒体文件路径
     */
    public static String TEMP_FILE_PATHNAME;

    @Value("#{'${static.file.path}' + '/temp'}")
    public void setTempFilePathname(String tempFilePathname) {
        CommonConstant.TEMP_FILE_PATHNAME = tempFilePathname;
    }

    public static String MEDIA_FILE_PATHNAME;

    @Value("#{'${MediaPath}' + '/task_{0}/user_{1}/{2}'}")
    public void setMediaFilePathname(String mediaFilePathname) {
        CommonConstant.MEDIA_FILE_PATHNAME = mediaFilePathname;
    }
    // 只包含 task 层级目录
    public static final String MEDIA_TASK_FOLDER_PATH = "D:/TJ_project/back_end/static/MediaFile/task_{0}";

    public static String HISTORY_MEDIA_FILE_PATHNAME;

    @Value("#{'${HistoryMediaPath}' + '/task_{0}/user_{1}/{2}'}")
    public void setHistoryMediaFilePathname(String historyMediaFilePathname) {
        CommonConstant.HISTORY_MEDIA_FILE_PATHNAME = historyMediaFilePathname;
    }

    /**
     * 数据个数
     */
    public static String DATACOUNT = "datacount";

    /**
     * 分页查询的PageSize
     */
    public static int PAGE_SIZE = 7;
}
