package com.docus.server.report.config;

import com.docus.server.report.util.TableJsonRead;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * 应用业务配置
 *
 * @author wyb
 */

public class SdRyReportHandledConfig {
    private final static TableJsonRead JSON_READ = new TableJsonRead();

    @Data
    private static class SdRyReportSystem {
        /**
         * 需要阻塞的报告来源系统,报告和描述信息分开推送
         */
        private List<String> blocking = new ArrayList<>();
        /**
         * 不处理的报告来源系统，job处理
         */
        private List<String> notHandled = new ArrayList<>();

        /**
         * 需要获取base64的报告来源系统，原job处理的直接移动过来
         */
        private List<String> fetchBase64 = new ArrayList<>();
    }

    public SdRyReportHandledConfig() {

    }

    public SdRyReportSystem getSdRyReportSystem() {
        return JSON_READ.Read("data-config", "sdry-report-system.json", SdRyReportSystem.class);
    }

    public boolean isBlocking(String systemName) {
        SdRyReportSystem sdRyReportSystem = getSdRyReportSystem();
        if (sdRyReportSystem != null) {
            List<String> blocking = sdRyReportSystem.getBlocking();
            return blocking.contains(systemName);
        }
        return false;
    }

    public boolean isNotHandled(String systemName) {
        SdRyReportSystem sdRyReportSystem = getSdRyReportSystem();
        if (sdRyReportSystem != null) {
            List<String> notHandled = sdRyReportSystem.getNotHandled();
            return notHandled.contains(systemName);
        }
        return false;
    }

    public boolean isFetchBase64(String systemName) {
        SdRyReportSystem sdRyReportSystem = getSdRyReportSystem();
        if (sdRyReportSystem != null) {
            List<String> getBase64System = sdRyReportSystem.getFetchBase64();
            return getBase64System.contains(systemName);
        }
        return false;
    }

    public static void main(String[] args) {
        SdRyReportHandledConfig sdRyReportHandledConfig = new SdRyReportHandledConfig();
        System.out.println(sdRyReportHandledConfig.getSdRyReportSystem());
        System.out.println(sdRyReportHandledConfig.isNotHandled("lis"));
        System.out.println(sdRyReportHandledConfig.isNotHandled("yx"));
        System.out.println(sdRyReportHandledConfig.isBlocking("yx"));
        System.out.println(sdRyReportHandledConfig.isBlocking("lis"));
        System.out.println(sdRyReportHandledConfig.isFetchBase64("cta"));
    }

}
