package com.docus.server.report.config;

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

import java.util.List;

public class TaskValidateConfig {
    private final static String CONFIG_PATH = "data-config";
    private final static String CONFIG_FILE_NAME = "task-validate-config.json";

    public static void main(String[] args) {
        CollectTaskConfig collectTaskConfig = getCollectTaskConfig("1");
        System.out.println(collectTaskConfig);
    }

    public static CollectTaskConfig getCollectTaskConfig(String collectorId) {
        TableJsonRead tableJsonRead = new TableJsonRead();
        String configContent = tableJsonRead.ReadContent(CONFIG_PATH, CONFIG_FILE_NAME);
        if (Func.isBlank(configContent)) {
            return null;
        }
        List<CollectTaskConfig> configs = Func.parseJsonArray(configContent, CollectTaskConfig.class);
        for (CollectTaskConfig config : configs) {
            if (collectorId.equals(config.getCollectorId())) {
                return config;
            }
        }
        return null;
    }

    @Data
    public static class CollectTaskConfig {
        private String collectorId;
        private List<CollectTaskFilterConfig> cancel;
    }

    @Data
    public static class CollectTaskFilterConfig {
        private ValidateConfig admissionDate;
        private ValidateConfig dischargeDate;
        private ValidateConfig admissionDepartment;
        private ValidateConfig dischargeDepartment;
    }

    @Data
    public static class ValidateConfig {
        private String operator;
        private String value;
        private Integer dataType;
        public boolean isEffective() {
            return dataType != null && Func.isNotBlank(operator) && Func.isNotBlank(value);
        }
    }


}
