import { VTableSheetEventType } from "../ts-types/spreadsheet-events";

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

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

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

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

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

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

          case VTableSheetEventType.SPREADSHEET_READY:
          case VTableSheetEventType.SPREADSHEET_DESTROYED:
          case VTableSheetEventType.SPREADSHEET_RESIZED:
          case VTableSheetEventType.CROSS_SHEET_FORMULA_CALCULATE_START:
          case 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 === VTableSheetEventType.FORMULA_ERROR ? event.cell && event.formula && event.error : event.type !== VTableSheetEventType.FORMULA_ADDED && event.type !== 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)}`;
    }
}
//# sourceMappingURL=event-validator.js.map