"use strict";

Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.EventValidator = void 0;

const spreadsheet_events_1 = require("../ts-types/spreadsheet-events");

class EventValidator {
    static validate(eventType, event) {
        if (void 0 === event) return !0;
        if (event && "object" != typeof event) return !1;
        switch (eventType) {
          case spreadsheet_events_1.VTableSheetEventType.SHEET_ADDED:
          case spreadsheet_events_1.VTableSheetEventType.SHEET_REMOVED:
          case spreadsheet_events_1.VTableSheetEventType.SHEET_RENAMED:
          case spreadsheet_events_1.VTableSheetEventType.SHEET_MOVED:
          case spreadsheet_events_1.VTableSheetEventType.SHEET_VISIBILITY_CHANGED:
            return this.validateSheetEvent(event);

          case spreadsheet_events_1.VTableSheetEventType.FORMULA_ERROR:
          case spreadsheet_events_1.VTableSheetEventType.FORMULA_ADDED:
          case spreadsheet_events_1.VTableSheetEventType.FORMULA_REMOVED:
          case spreadsheet_events_1.VTableSheetEventType.FORMULA_CALCULATE_START:
          case spreadsheet_events_1.VTableSheetEventType.FORMULA_CALCULATE_END:
          case spreadsheet_events_1.VTableSheetEventType.FORMULA_DEPENDENCY_CHANGED:
            return this.validateFormulaEvent(event);

          case spreadsheet_events_1.VTableSheetEventType.DATA_LOADED:
            return this.validateDataEvent(event);

          case spreadsheet_events_1.VTableSheetEventType.IMPORT_START:
          case spreadsheet_events_1.VTableSheetEventType.IMPORT_COMPLETED:
          case spreadsheet_events_1.VTableSheetEventType.IMPORT_ERROR:
            return this.validateImportEvent(event);

          case spreadsheet_events_1.VTableSheetEventType.EXPORT_START:
          case spreadsheet_events_1.VTableSheetEventType.EXPORT_COMPLETED:
          case spreadsheet_events_1.VTableSheetEventType.EXPORT_ERROR:
            return this.validateExportEvent(event);

          case spreadsheet_events_1.VTableSheetEventType.CROSS_SHEET_REFERENCE_UPDATED:
            return this.validateCrossSheetEvent(event);

          case spreadsheet_events_1.VTableSheetEventType.SPREADSHEET_READY:
          case spreadsheet_events_1.VTableSheetEventType.SPREADSHEET_DESTROYED:
          case spreadsheet_events_1.VTableSheetEventType.SPREADSHEET_RESIZED:
          case spreadsheet_events_1.VTableSheetEventType.CROSS_SHEET_FORMULA_CALCULATE_START:
          case spreadsheet_events_1.VTableSheetEventType.CROSS_SHEET_FORMULA_CALCULATE_END:
          default:
            return !0;
        }
    }
    static validateSheetEvent(event) {
        return event.sheetKey && "string" == typeof event.sheetKey;
    }
    static validateFormulaEvent(event) {
        return !(!event.sheetKey || "string" != typeof event.sheetKey) && (event.type === spreadsheet_events_1.VTableSheetEventType.FORMULA_ERROR ? event.cell && event.formula && event.error : event.type !== spreadsheet_events_1.VTableSheetEventType.FORMULA_ADDED && event.type !== spreadsheet_events_1.VTableSheetEventType.FORMULA_REMOVED || event.cell && "number" == typeof event.cell.row && "number" == typeof event.cell.col);
    }
    static validateDataEvent(event) {
        return event.sheetKey && "string" == typeof event.sheetKey;
    }
    static validateImportEvent(event) {
        return event.fileType && [ "xlsx", "xls", "csv" ].includes(event.fileType);
    }
    static validateExportEvent(event) {
        return event.fileType && [ "xlsx", "csv" ].includes(event.fileType) && "boolean" == typeof event.allSheets;
    }
    static validateCrossSheetEvent(event) {
        return event.sourceSheetKey && "string" == typeof event.sourceSheetKey && Array.isArray(event.targetSheetKeys) && "number" == typeof event.affectedFormulaCount;
    }
    static getErrorMessage(eventType, event) {
        return this.validate(eventType, event) ? "" : `事件数据验证失败: ${eventType} - ${JSON.stringify(event)}`;
    }
}

exports.EventValidator = EventValidator;
//# sourceMappingURL=event-validator.js.map