package com.ms.biz.consts;

import java.time.LocalDate;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;

import cn.hutool.core.util.ObjectUtil;

public class RedisKeyConst {

    public static final String MOVE_PRODUCT_PUBLISH_BUFFER_LOCK_KEY = "move_product_publish_buffer_lock_key";

    public static final String MOVE_MATERIAL_AUDIT_BUFFER_TASK_LOCK_KEY = "move_material_audit_buffer_task_lock_key";

    public static final String MOVE_UNLOCK_TASK_LOCK_KEY = "move_unlock_task_lock_key";

    public static final String MOVE_REPLENISH_TASK_LOCK_KEY = "move_replenish_task_lock_key";

    public static final String MOVE_CHECK_AUDIT_STATUS_TIMEOUT_TASK_LOCK_KEY = "move_check_audit_status_timeout_task_lock_key";

    public static final String PRODUCT_GET_UNAUTHORIZED = "product_get_unauthorized";
    public static final String MOVE_PRODUCT_PUBLISH_TO_PIC_QUEUE = "move_product_publish_to_pic_queue";

    public static final String MATERIAL_AUDIT_STATUS_QUEUE = "material_audit_status_queue";

    public static final String REDIS_TYPE_BIZ_CACHE = "bizCache";
    public static final String REDIS_TYPE_STAT_CACHE = "statCache";
    public static final String REDIS_TYPE_SOLID_CACHE = "solidCache";
    public static final String REDIS_TYPE_TIMER_CACHE = "timerCache";

    public static final String MOVE_PRODUCT_PUBLISH_QUEUE_SELF = "dd_move_item_publish_queue_self";
    public static final String MOVE_PRODUCT_PUBLISH_QUEUE = "dd_move_item_publish_queue";

    public static final String SHOP_DENY_REQUEST_SHOP_IDS = "dd_shop_deny_request_shop_ids";
    public static final String SHOP_REQUEST_TS_MAP = "dd_shop_request_ts_map";
    public static final String SHOP_REQUEST_ABNORMAL_SET = "dd_shop_request_abnormal_set";
    public static final String SHOP_MOVE_PUBLISH_COUNT = "dd_shop_move_publish_count";
    public static final String SHOP_MOVE_PUBLISH_COST_TIME_COUNT = "dd_shop_move_publish_cost_time_count";

    public static final String ADMIN_SELF_SHOP_INFO = "dd_admin_self_shop_info";

    public static final String MOVE_SETTING_SEARCH_JSON_TS = "dd_move_setting_search_json_ts";

    public static final String MOVE_REWRITE_CID_RULES = "dd_move_rewrite_cid_rules";

    public static final String LEAF_CATE_LIST = "dd_leaf_cate_list_v2";

    public static final String OP_ORDER_PURCHASE_OUTSTORAGE_BUFFER = "op_order_purchase_outstorage_buffer";

    public static final String MOVE_IMPORT_TASK_QUEUE_SELF = "move_import_task_queue_self";
    public static final String MOVE_IMPORT_TASK_QUEUE = "move_import_task_queue";
    public static final String MOVE_IMPORT_TASK_PARSE_DETAIL_SECONDS_MAP_KEY = "move_import_task_parse_detail_seconds_map";
    public static final String MOVE_IMPORT_TASK_PARSE_COUNT_MAP_KEY = "move_import_task_parse_count_map";

    public static final String AREA_TB_PROVINCE_LIST_KEY = "area_tb_province_list";
    public static final String AREA_TB_CITY_ID_AND_CITY_NAME_MAP_KEY = "area_tb_city_id_and_city_name_map";
    public static final String AREA_TB_CITY_LIST_KEY = "area_tb_city_list";

    public static final String SEARCH_MOVE_SETTING_FIELD_ARR = "honor_search_move_setting_filed_arr";

    public static final String MOVE_GROUP_MOVE_COUNT_MAP = "honor_dd_move_group_move_count_map";
    public static final String MOVE_GROUP_MOVE_STATUS_COUNT = "honor_dd_move_group_move_status_count";

    public static final String DD_LOGISTICS_COMPANY_CODE_AND_COMPANY_ID_MAP = "dd_logistics_company_code_and_company_id_map";

    public static final String ORDER_STAT_BIZ_KEY = "shop_order_stat";
    public static final String PURCHASE_ORDER_STAT_BIZ_KEY = "purchase_order_stat";

    public static final String AFTER_SALE_REJECT_REASON_CODE_LIST = "after_sale_reject_reason_code_list";

    public static final String RSYNC_OP_ORDER_QUEUE_COMPLETED_MAP = "rsync_op_order_queue_completed_map";

    public static final String ORDER_STAT_CHANGE_SHOP_ID_AND_CHANGE_TIME_MAP = "order_stat_change_shop_id_and_change_time_map";

    public static final String DD_AREA_PROVINCE_LIST = "dd_area_province_list";
    public static final String DD_AREA_CITY_LIST = "dd_area_city_list";
    public static final String DS_AUTO_PURCHASE_WHITELIST = "ds_auto_purchase_whitelist";

    public static final String WAYBILL_PRINT_DETAIL_GET_HASH_MAP = "waybill_print_detail_get_hash_map";

    public static final String USER_REQUEST_LOG_INFO = "user_request_log_info";

    public static final String JMONITOR_LOG = "jmonitor_log";
    public static final String DB_ERROR_LOG = "db_error_log";

    public static final String SHOP_ALL_ROUTE_REQ_STAT_LIST_HEAP_UP_WARNING_FLAG = "shop_all_route_req_stat_list_heap_up_warning_flag";

    public static final String STOP_PULL_DY_CLOUD_DATA = "stop_pull_dy_cloud_data";

    public static final String TIMER_MONITOR_TIMER_CODE_LOCK_KEY = "timer:monitor_timer_code";

    public static final String RSYNC_CATEGORY_QUEUE = "rsync_category_queue";

    public static final int KEY_TYPE_NOT_FOUND = 0;
    public static final int KEY_TYPE_STRING = 1;
    public static final int KEY_TYPE_SET = 2;
    public static final int KEY_TYPE_LIST = 3;
    public static final int KEY_TYPE_ZSET = 4;
    public static final int KEY_TYPE_HASH = 5;
    public static String shopMovePublishCount = "dd_shop_move_publish_count";
    public static String shopMovePublishCostTimeCount = "dd_shop_move_publish_cost_time_count";

    public static String buildOrderRsyncCountStatMapKey() {
        LocalDate currentDate = LocalDate.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
        return "order_rsync_count_stat_map_" + currentDate.format(formatter);
    }

    public static String buildRsyncOpOrderQueueCompletedMapLockKey(Long queueId) {
        return "rsync_op_order_queue_completed_map_lock_" + queueId;
    }

    public static String buildPayingNewOrderStatBizKey(Date date) {
        LocalDate currentDate = ObjectUtil.isEmpty(date) ? LocalDate.now() : date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
        return "paying_new_order_stat_" + currentDate.format(formatter);
    }

    public static String buildOrderStatBizKey(boolean isSelf) {
        return ORDER_STAT_BIZ_KEY + (isSelf ? "_self" : "");
    }

    public static String getQueueRedisKey(String queueName, boolean isAdminSelf) {
        if (isAdminSelf) {
            return (queueName.concat("_self"));
        } else {
            return queueName;
        }
    }
}
