package com.yfd.platform.uavsystem.enums;

import lombok.Getter;

import java.util.stream.Stream;

/**
 * 电网资源业务中台维护服务地址枚举
 *
 * @author qigc
 * @date 2023-04-26 17:17
 */
@Getter
public enum WMCenterUrlEnum {
    /**
     * 获取28个维护服务token
     */
    GET_TOKEN("获取28个维护服务token", "/psr-auth/oauth/accessToken", "00"),
    /**
     * 新增
     */
    INSPECTION_PLAN_SAVE("新增巡视计划", "/WMCenter/patrol/planCreate", "01"),
    INSPECTION_TASK_SAVE("新增巡视任务", "/WMCenter/patrol/workOrderCreate", "02"),
    INSPECTION_RECORDS_SAVE("新增巡视记录", "/WMCenter/patrol/recordCreate", "03"),

    /**
     * 修改
     */
    INSPECTION_PLAN_EDIT("修改巡视计划", "/WMCenter/patrol/planUpdate", "10"),
    INSPECTION_TASK_EDIT("修改巡视任务", "/WMCenter/patrol/workOrderUpdate", "11"),
    INSPECTION_RECORDS_EDIT("修改巡视记录", "/WMCenter/patrol/recordUpdate", "12"),


    /**
     * 查询服务
     */
    INSPECTION_PLAN_QUERY("查询巡视计划", "/WMCenter/patrol/planList", "20"),
    INSPECTION_TASK_QUERY("查询巡视任务", "/WMCenter/patrol/workOrderList", "21"),
    INSPECTION_RECORDS_QUERY("查询巡视记录", "/WMCenter/patrol/recordList", "22"),
    DEFECT_RECORDS_QUERY("查询缺陷记录", "/WMCenter/defect/inquireDefect", "23"),

    /**
     * 查看
     */
    INSPECTION_PLAN_SHOW("查看巡视计划", "/WMCenter/patrol/planQuery", "30"),
    INSPECTION_TASK_SHOW("查看巡视任务", "/WMCenter/patrol/workOrderQuery", "31"),
    INSPECTION_RECORDS_SHOW("查看巡视记录", "/WMCenter/patrol/recodeQuery", "32"),
    DEFECT_RECORDS_SHOW("查看缺陷记录", "/WMCenter/defect/viewDefect", "33"),



    /**
     * 附件下载
     */
    FILE_DOWNLOAD("附件下载","/WMCenter/defect/record/fileDownload","40"),
    ;


    private final String name;
    private final String url;
    private final String code;

    WMCenterUrlEnum(String name, String url, String code) {
        this.name = name;
        this.url = url;
        this.code = code;
    }

    public String getValue() {
        return this.url;
    }

    public static WMCenterUrlEnum toCode(String code) {
        return Stream.of(WMCenterUrlEnum.values()).filter(p -> p.code.equals(code)).findAny().orElse(null);
    }

    public static WMCenterUrlEnum toUrlAndType(String code) {
        return Stream.of(WMCenterUrlEnum.values()).filter(p -> p.code.equals(code)).findAny().orElse(null);
    }

    /**
     * <p>
     * 根据code获取名称
     * </p>
     *
     * @param code 值
     * @return {@link String} 返回结果
     * @Author hu shi hua
     * @date 2024/3/15 11:00
     * @version 1.0.0
     */
    public static String entryCodeReverName(String code) {
        for (WMCenterUrlEnum s : values()) {
            if (s.getCode().equals(code)) {
                return s.getName();
            }
        }
        return "";
    }

    /**
     * <p>
     * 根据url获取枚举信息
     * </p>
     *
     * @param url
     * @return {@link WMCenterUrlEnum} 返回结果
     * @Author hu shi hua
     * @date 2024/3/15 11:01
     * @version 1.0.0
     */
    public static WMCenterUrlEnum entryCodeRever(String url) {
        for (WMCenterUrlEnum s : values()) {
            if (s.getUrl().equals(url)) {
                return s;
            }
        }
        return null;
    }
}
