class ValidationReport {
  final bool isValid;
  final bool dataIntegrity;
  final bool businessRulesValid;

  const ValidationReport({
    required this.isValid,
    required this.dataIntegrity,
    required this.businessRulesValid,
  });
}

class MaintenanceDataValidator {
  static Future<ValidationReport> validate({
    required List<Map<String, dynamic>> maintenanceData,
    required List<Map<String, dynamic>> equipmentHistoryData,
  }) async {
    // 기본 무결성: equipment_history_id가 존재하고 history 목록에 포함
    final historyIds = equipmentHistoryData.map((e) => e['id']).toSet();
    bool integrity = true;
    for (final m in maintenanceData) {
      final hid = m['equipment_history_id'];
      if (hid == null || !historyIds.contains(hid)) {
        integrity = false;
        break;
      }
    }

    // 간단한 비즈니스 규칙: status 가 지정 집합에 포함
    const allowed = {'scheduled', 'upcoming', 'overdue'};
    bool business = maintenanceData.every((m) => allowed.contains(m['status']));

    final ok = integrity && business;
    return ValidationReport(
      isValid: ok,
      dataIntegrity: integrity,
      businessRulesValid: business,
    );
  }
}

