package net.northking.cctp.upperComputer.enums;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Date;

/**
 * 文件业务类型编码枚举类
 */
public enum FileBusinessTypeEnum {

    MOBILE_RECORD_SCREENSHOT("移动设备录制截图文件", "MOBILE_RECORD_SCREENSHOT", null),
    MOBILE_TASK_SCREENSHOT("移动设备任务截图文件", "MOBILE_TASK_SCREENSHOT", null),
    MOBILE_TASK_VIDEO("移动设备视频文件", "MOBILE_TASK_VIDEO", null),
    MOBILE_TASK_DEVICE_PERFORMANCE("移动设备性能文件", "MOBILE_TASK_DEVICE_PERFORMANCE", null),
    MOBILE_TASK_APP_PERFORMANCE("移动设备app性能文件", "MOBILE_TASK_APP_PERFORMANCE", null),
    MOBILE_TASK_PERFORMANCE_SUMMARY("移动设备app性能，设备性能汇总文件", "MOBILE_TASK_PERFORMANCE_SUMMARY", null),
    BATCH_TASK_PERFORMANCE_SUMMARY("移动设备批次任务结束性能汇总文件", "BATCH_TASK_PERFORMANCE_SUMMARY", null),
    MOBILE_TASK_LOG("移动设备日志文件", "MOBILE_TASK_LOG", null),
    PC_RECORD_SCREENSHOT("pc录制截图文件", "PC_RECORD_SCREENSHOT", null),
    PC_TASK_SCREENSHOT("任务截图文件", "PC_TASK_SCREENSHOT", null),
    PC_TASK_VIDEO("任务视频文件", "PC_TASK_VIDEO", null),
    TASK_EXECUTE_RESULT("任务执行结果文件", "TASK_EXECUTE_RESULT", null),
    COMMON_SCRIPT("一般脚本文件", "COMMON_SCRIPT", null),
    SCENE_SCRIPT("场景脚本文件", "SCENE_SCRIPT", null),
    COMMON_SCRIPT_INPUT_DATA_SET("一般脚本草稿输入项文件", "COMMON_SCRIPT_INPUT_DATA_SET", null),
    COMMON_SCRIPT_VERSION_INPUT_DATA_SET("一般脚本草稿输入项版本文件", "COMMON_SCRIPT_VERSION_INPUT_DATA_SET", null),
    SCENE_SCRIPT_INPUT_DATA_SET("场景脚本草稿输入项文件", "SCENE_SCRIPT_INPUT_DATA_SET", null),
    SCENE_SCRIPT_VERSION_INPUT_DATA_SET("场景脚本草稿输入项版本文件", "SCENE_SCRIPT_VERSION_INPUT_DATA_SET", null),
    INPUT_DATA_SET("用例集输入项文件", "INPUT_DATA_SET", null),
    BUSINESS_COMPONENT_SCRIPT("业务组件脚本文件", "BUSINESS_COMPONENT_SCRIPT", null),
    APP_FILE("app文件", "APP_FILE", null),
    STATIC_DATA_SET("静态数据集数据文件", "STATIC_DATA_SET", null),
    STATIC_DATA_SET_ENV("静态数据集环境数据文件", "STATIC_DATA_SET_ENV", null),
    DATA_RUL_RESOURCE_PACKAGE("模糊测试数据资源包文件", "DATA_RUL_RESOURCE_PACKAGE", null),
    ELEMENT_IMAGE("元素库图片", "ELEMENT_IMAGE", null),
    BASIC_ELEMENT_LIB("平台基础组件上传文件", "BASIC_ELEMENT_LIB", null),

    OTHER_FILE("其他附件", "OTHER_FILE", null);
    /**
     * 文件类型名称
     */
    private String name;
    /**
     * 文件类型编码
     */
    private String code;
    /**
     * 有效期（天）
     */
    private Long day;

    FileBusinessTypeEnum(String name, String code, Long day) {
        this.name = name;
        this.code = code;
        this.day = day;
    }

    public static FileBusinessTypeEnum getFileBusinessTypeByCode(String code) {
        if (code == null) {
            return null;
        }
        FileBusinessTypeEnum fileBusinessType = null;
        for (FileBusinessTypeEnum FileTypeEnum : FileBusinessTypeEnum.values()) {
            if (FileTypeEnum.code.equals(code)) {
                fileBusinessType = FileTypeEnum;
                break;
            }
        }
        return fileBusinessType;
    }

    public String getName() {
        return name;
    }

    public String getCode() {
        return code;
    }

    public Long getDay() {
        return day;
    }

    /**
     * 根据当前时间，获取过期时间
     * @return
     */
    public Date getOverTime(){
        if (day == null){
            return null;
        }
        LocalDateTime localDateTime = LocalDateTime.now().plusDays(day);
        return Date.from(localDateTime.atZone(ZoneOffset.systemDefault()).toInstant());
    }
}