All files / services advancedGeometryService.js

0% Statements 0/156
0% Branches 0/62
0% Functions 0/14
0% Lines 0/142

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
const logger = require('../utils/logger');
 
/**
 * AdvancedGeometryService - Avancerede geometriberegninger for tagarbejde
 * Inkluderer højdeberegninger, SVG illustrationer og integration med materialer
 */
class AdvancedGeometryService {
  constructor(databaseService) {
    this.db = databaseService;
  }
 
  /**
   * Beregn udvidede geometridata inklusiv højder og materialer
   */
  async calculateAdvancedGeometry(geometryInput) {
    try {
      const {
        roofType = 'betontegl', // Default tagtype
        width,
        length,
        roofLength = length,
        roofWidth = width,
        roofPitch = 30,
        pitch = roofPitch,
        ridgeHeight = null, // Højde fra stern til kip (lodret mål)
        wallHeight = 0, // Væghøjde til tagkant
        hasComplexFeatures = false
      } = geometryInput;
 
      // Normalisér parametre
      const normalizedLength = roofLength || length;
      const normalizedWidth = roofWidth || width;
      const normalizedPitch = pitch || roofPitch;
 
      // Basis areal beregning
      const baseArea = normalizedLength * normalizedWidth;
 
      // Beregn forskellige højder og længder
      const heightCalculations = this.calculateHeights(
        normalizedWidth, normalizedLength, normalizedPitch, ridgeHeight, wallHeight
      );
 
      // Beregn vindskedelængder baseret på geometri
      const windboardCalculations = this.calculateWindboards(
        normalizedLength, normalizedWidth, roofType, heightCalculations
      );
 
      // Beregn materialekvantiteter baseret på geometri
      const materialQuantities = this.calculateMaterialQuantities(
        baseArea, heightCalculations, windboardCalculations, roofType
      );
 
      // Generer SVG illustration
      const svgIllustration = this.generateSVGIllustration(
        normalizedLength, normalizedWidth, heightCalculations, roofType
      );
 
      const result = {
        basicDimensions: {
          length: normalizedLength,
          width: normalizedWidth,
          baseArea: Math.round(baseArea * 100) / 100,
          roofType: roofType,
          pitch: normalizedPitch
        },
        heightCalculations,
        windboardCalculations,
        materialQuantities,
        svgIllustration,
        complexity: this.calculateComplexityFactor(geometryInput),
        estimatedWorkHours: this.estimateWorkHours(baseArea, roofType, hasComplexFeatures),
        recommendations: this.generateRecommendations(baseArea, roofType, heightCalculations)
      };
 
      logger.info('Advanced geometry calculated', {
        roofType,
        baseArea,
        totalMaterialArea: materialQuantities.totalCoverage
      });
 
      return result;
    } catch (error) {
      logger.error('Error calculating advanced geometry:', error);
      throw error;
    }
  }
 
  /**
   * Beregn forskellige højder på taget
   */
  calculateHeights(roofWidth, roofLength, roofPitch, ridgeHeight = null, wallHeight = 0) {
    const pitchRadians = (roofPitch * Math.PI) / 180;
    
    // Hvis ridgeHeight er givet, brug det, ellers beregn fra pitch
    const calculatedRidgeHeight = ridgeHeight || (roofWidth / 2) * Math.tan(pitchRadians);
    
    // Samlede højder
    const totalRidgeHeight = wallHeight + calculatedRidgeHeight;
    const eaveHeight = wallHeight; // Højde til tagkant
    
    // Skrålængde (rafter length)
    const rafterLength = (roofWidth / 2) / Math.cos(pitchRadians);
    
    // Tagflade areal (justeret for hældning)
    const slopeArea = roofLength * rafterLength * 2; // Begge sider af taget
 
    return {
      ridgeHeight: Math.round(calculatedRidgeHeight * 100) / 100, // Højde fra stern til kip
      totalRidgeHeight: Math.round(totalRidgeHeight * 100) / 100, // Total højde fra jord
      eaveHeight: Math.round(eaveHeight * 100) / 100, // Højde til tagkant
      rafterLength: Math.round(rafterLength * 100) / 100, // Spær længde
      slopeArea: Math.round(slopeArea * 100) / 100, // Faktisk tagflade areal
      pitchAngle: roofPitch,
      measurements: {
        wallHeight,
        roofSpan: roofWidth,
        roofRun: roofLength,
        rise: calculatedRidgeHeight,
        run: roofWidth / 2
      }
    };
  }
 
  /**
   * Beregn vindskedelængder
   */
  calculateWindboards(roofLength, roofWidth, roofType, heightCalculations) {
    const { rafterLength } = heightCalculations;
    
    // Vindskeder langs gavlene (følger taghældningen)
    const gableBoardLength = rafterLength * 2; // Begge sider af gavlen
    const gableBoardTotal = gableBoardLength * 2; // Begge gavle
    
    // Vindskeder langs langsiderne (vandret)
    const eavesBoardLength = roofLength * 2; // Begge langsider
    
    // Tagryg vindskede (øverst på taget)
    const ridgeBoardLength = roofLength;
    
    // Total vindskedelængde
    const totalWindboardLength = gableBoardTotal + eavesBoardLength + ridgeBoardLength;
 
    return {
      gableBoards: {
        lengthPerGable: Math.round(gableBoardLength * 100) / 100,
        totalLength: Math.round(gableBoardTotal * 100) / 100,
        description: 'Vindskeder langs gavlene (følger taghældningen)'
      },
      eavesBoards: {
        lengthPerSide: roofLength,
        totalLength: Math.round(eavesBoardLength * 100) / 100,
        description: 'Vindskeder langs tagkanterne (vandrette)'
      },
      ridgeBoard: {
        length: Math.round(ridgeBoardLength * 100) / 100,
        description: 'Vindskede langs tagryggen'
      },
      totalLength: Math.round(totalWindboardLength * 100) / 100,
      recommendedDimensions: this.getRecommendedWindboardDimensions(roofType),
      cuttingAngles: {
        gableBoardAngle: heightCalculations.pitchAngle,
        eavesBoardAngle: 0, // Vandrette
        ridgeBoardAngle: 0
      }
    };
  }
 
  /**
   * Beregn materialekvantiteter baseret på geometri
   */
  calculateMaterialQuantities(baseArea, heightCalculations, windboardCalculations, roofType) {
    const { slopeArea } = heightCalculations;
    
    // Basis materialer med spild/overlap
    const roofCovering = Math.ceil(slopeArea * 1.1); // 10% spild
    const underlay = Math.ceil(slopeArea * 1.05); // 5% overlap
    const insulation = Math.ceil(baseArea * 1.02); // 2% spild
    
    // Vindskeder
    const windboards = Math.ceil(windboardCalculations.totalLength * 1.05); // 5% spild
    
    // Beslag og fastgørelse
    const fasteners = this.calculateFasteners(slopeArea, roofType);
    
    // Specialmaterialer baseret på tagtype
    const specialMaterials = this.getSpecialMaterials(roofType, slopeArea, heightCalculations);
 
    return {
      roofCovering: {
        area: roofCovering,
        unit: 'm²',
        description: 'Tagdækning (inkl. 10% spild)'
      },
      underlay: {
        area: underlay,
        unit: 'm²',
        description: 'Undertag (inkl. 5% overlap)'
      },
      insulation: {
        area: insulation,
        unit: 'm²',
        description: 'Isolering'
      },
      windboards: {
        length: windboards,
        unit: 'løbm',
        description: 'Vindskeder total',
        breakdown: windboardCalculations
      },
      fasteners,
      specialMaterials,
      totalCoverage: roofCovering,
      wasteFactors: {
        roofCovering: 0.1,
        underlay: 0.05,
        insulation: 0.02,
        windboards: 0.05
      }
    };
  }
 
  /**
   * Beregn beslag og fastgørelse
   */
  calculateFasteners(area, roofType) {
    const fasteners = {};
 
    switch (roofType.toLowerCase()) {
      case 'betontegl':
        fasteners.hooks = Math.ceil(area * 0.8); // Tagcentraler
        fasteners.screws = Math.ceil(area * 6); // Skruer til vindskeder
        break;
      case 'b7':
      case 'b6':
        fasteners.screws = Math.ceil(area * 8); // Tagskruer til plader
        fasteners.ridgeCap = Math.ceil(area * 0.1); // Ryggesting
        break;
      case 'vingetegl':
        fasteners.hooks = Math.ceil(area * 0.7);
        fasteners.mortar = Math.ceil(area * 2); // kg mørtel
        break;
      default:
        fasteners.screws = Math.ceil(area * 6);
        break;
    }
 
    return fasteners;
  }
 
  /**
   * Hent specialmaterialer baseret på tagtype
   */
  getSpecialMaterials(roofType, area, heightCalculations) {
    const specialMaterials = {};
 
    switch (roofType.toLowerCase()) {
      case 'betontegl':
        specialMaterials.ridgeTiles = Math.ceil(heightCalculations.measurements.roofRun / 0.33); // Rygstenslængde
        specialMaterials.ventilation = Math.ceil(area / 50); // Ventilationsziegel
        break;
      case 'b7':
      case 'b6':
        specialMaterials.ridgeCapping = Math.ceil(heightCalculations.measurements.roofRun);
        specialMaterials.flashingStrips = Math.ceil(heightCalculations.measurements.roofRun * 2);
        break;
      case 'vingetegl':
        specialMaterials.ridgeTiles = Math.ceil(heightCalculations.measurements.roofRun / 0.30);
        specialMaterials.hipTiles = Math.ceil(area / 100); // Skrånningsten hvis relevante
        break;
    }
 
    return specialMaterials;
  }
 
  /**
   * Generer SVG illustration af taget med mål
   */
  generateSVGIllustration(roofLength, roofWidth, heightCalculations, roofType) {
    const { ridgeHeight, rafterLength } = heightCalculations;
    
    // SVG dimensioner (skaleret)
    const svgWidth = 400;
    const svgHeight = 300;
    const scale = Math.min(svgWidth / (roofWidth + 2), svgHeight / (ridgeHeight + roofWidth/2 + 2));
    
    // Centrering
    const centerX = svgWidth / 2;
    const centerY = svgHeight - 50;
    
    // Skalerede dimensioner
    const scaledWidth = roofWidth * scale;
    const scaledHeight = ridgeHeight * scale;
    const scaledRafterLength = rafterLength * scale;
 
    const svgElements = [];
 
    // Baggrund
    svgElements.push(`<rect width="${svgWidth}" height="${svgHeight}" fill="#f8f9fa" stroke="#dee2e6"/>`);
 
    // Tag outline (set forfra)
    const leftX = centerX - scaledWidth / 2;
    const rightX = centerX + scaledWidth / 2;
    const topY = centerY - scaledHeight;
    const bottomY = centerY;
 
    // Venstre tagflade
    svgElements.push(`
      <path d="M ${leftX} ${bottomY} L ${centerX} ${topY} L ${centerX} ${topY - 10} L ${leftX} ${bottomY - 10} Z" 
            fill="#8B4513" stroke="#654321" stroke-width="2" opacity="0.8"/>
    `);
 
    // Højre tagflade
    svgElements.push(`
      <path d="M ${centerX} ${topY} L ${rightX} ${bottomY} L ${rightX} ${bottomY - 10} L ${centerX} ${topY - 10} Z" 
            fill="#A0522D" stroke="#654321" stroke-width="2" opacity="0.8"/>
    `);
 
    // Tagryg
    svgElements.push(`
      <line x1="${centerX}" y1="${topY}" x2="${centerX}" y2="${topY - 10}" 
            stroke="#654321" stroke-width="3"/>
    `);
 
    // Målelinjer og tekster
    // Bredde
    svgElements.push(`
      <line x1="${leftX}" y1="${bottomY + 20}" x2="${rightX}" y2="${bottomY + 20}" 
            stroke="#007bff" stroke-width="1" marker-end="url(#arrowhead)" marker-start="url(#arrowhead)"/>
      <text x="${centerX}" y="${bottomY + 35}" text-anchor="middle" font-size="12" fill="#007bff">
        ${roofWidth}m (bredde)
      </text>
    `);
 
    // Højde (lodret fra stern til kip)
    svgElements.push(`
      <line x1="${centerX - 15}" y1="${bottomY}" x2="${centerX - 15}" y2="${topY}" 
            stroke="#dc3545" stroke-width="1" marker-end="url(#arrowhead)" marker-start="url(#arrowhead)"/>
      <text x="${centerX - 25}" y="${centerY - scaledHeight/2}" text-anchor="middle" font-size="12" fill="#dc3545" 
            transform="rotate(-90, ${centerX - 25}, ${centerY - scaledHeight/2})">
        ${ridgeHeight}m (højde)
      </text>
    `);
 
    // Spærlængde
    svgElements.push(`
      <line x1="${leftX}" y1="${bottomY}" x2="${centerX}" y2="${topY}" 
            stroke="#28a745" stroke-width="2" stroke-dasharray="5,5" opacity="0.7"/>
      <text x="${leftX + 20}" y="${bottomY - scaledHeight/3}" font-size="11" fill="#28a745">
        Spær: ${rafterLength}m
      </text>
    `);
 
    // Pile definitioner
    const arrowDef = `
      <defs>
        <marker id="arrowhead" markerWidth="10" markerHeight="7" 
                refX="0" refY="3.5" orient="auto">
          <polygon points="0 0, 10 3.5, 0 7" fill="#007bff"/>
        </marker>
      </defs>
    `;
 
    // Titel og informationer
    svgElements.push(`
      <text x="${svgWidth/2}" y="25" text-anchor="middle" font-size="16" font-weight="bold" fill="#333">
        ${this.getRoofTypeDisplayName(roofType)} - Geometri
      </text>
    `);
 
    // Informationsboks
    const infoY = 50;
    svgElements.push(`
      <rect x="10" y="${infoY}" width="120" height="80" fill="white" stroke="#ddd" rx="5"/>
      <text x="15" y="${infoY + 15}" font-size="11" fill="#666">Areal: ${heightCalculations.slopeArea}m²</text>
      <text x="15" y="${infoY + 30}" font-size="11" fill="#666">Hældning: ${heightCalculations.pitchAngle}°</text>
      <text x="15" y="${infoY + 45}" font-size="11" fill="#666">Længde: ${roofLength}m</text>
      <text x="15" y="${infoY + 60}" font-size="11" fill="#666">Type: ${roofType}</text>
    `);
 
    // Samle SVG
    const svgContent = `
      <svg width="${svgWidth}" height="${svgHeight}" xmlns="http://www.w3.org/2000/svg">
        ${arrowDef}
        ${svgElements.join('\n')}
      </svg>
    `;
 
    return {
      svg: svgContent,
      dimensions: {
        width: svgWidth,
        height: svgHeight
      },
      measurements: {
        roofWidth,
        roofLength,
        ridgeHeight,
        rafterLength,
        area: heightCalculations.slopeArea
      }
    };
  }
 
  /**
   * Hent anbefalede vindskededimensioner
   */
  getRecommendedWindboardDimensions(roofType) {
    const dimensions = {
      'betontegl': { width: 25, height: 200, description: '25x200mm træ til betontegl' },
      'b7': { width: 22, height: 175, description: '22x175mm træ til B7 tagplader' },
      'b6': { width: 22, height: 150, description: '22x150mm træ til B6 tagplader' },
      'vingetegl': { width: 25, height: 200, description: '25x200mm træ til vingetegl' },
      'røde_teglsten': { width: 25, height: 225, description: '25x225mm træ til røde teglsten' }
    };
 
    // Håndter undefined, null eller tomme strings
    if (!roofType || typeof roofType !== 'string') {
      return dimensions['betontegl'];
    }
 
    return dimensions[roofType.toLowerCase()] || dimensions['betontegl'];
  }
 
  /**
   * Beregn kompleksitetsfaktor
   */
  calculateComplexityFactor(geometryInput) {
    let complexity = 1.0;
    const { roofType, roofPitch, hasComplexFeatures } = geometryInput;
 
    // Tagtype påvirkning
    switch (roofType?.toLowerCase()) {
      case 'fladt_tag': complexity *= 0.8; break;
      case 'skraat_tag': complexity *= 1.0; break;
      case 'mansard': complexity *= 1.4; break;
      case 'komplekst': complexity *= 1.6; break;
    }
 
    // Hældning påvirkning
    if (roofPitch > 45) complexity *= 1.3;
    else if (roofPitch > 35) complexity *= 1.1;
    else if (roofPitch < 15) complexity *= 1.2; // Meget flade tage er også svære
 
    // Komplekse features
    if (hasComplexFeatures) complexity *= 1.2;
 
    return Math.round(complexity * 100) / 100;
  }
 
  /**
   * Estimer arbejdstimer
   */
  estimateWorkHours(area, roofType, hasComplexFeatures) {
    let hoursPerSqm = 0.8; // Basis timer per m²
 
    // Juster baseret på tagtype
    switch (roofType?.toLowerCase()) {
      case 'betontegl': hoursPerSqm = 1.2; break;
      case 'b7': hoursPerSqm = 0.9; break;
      case 'b6': hoursPerSqm = 1.0; break;
      case 'vingetegl': hoursPerSqm = 1.4; break;
      case 'røde_teglsten': hoursPerSqm = 1.5; break;
    }
 
    if (hasComplexFeatures) hoursPerSqm *= 1.3;
 
    const totalHours = area * hoursPerSqm;
    return Math.round(totalHours * 10) / 10;
  }
 
  /**
   * Generer anbefalinger baseret på geometri
   */
  generateRecommendations(area, roofType, heightCalculations) {
    const recommendations = [];
 
    // Areal anbefalinger
    if (area > 200) {
      recommendations.push({
        type: 'warning',
        title: 'Stort tagprojekt',
        message: 'Dette er et stort tagprojekt. Overvej at opdele i faser og sørg for tilstrækkelig mandskab.'
      });
    }
 
    // Højde anbefalinger
    if (heightCalculations.ridgeHeight > 8) {
      recommendations.push({
        type: 'safety',
        title: 'Høj bygning',
        message: 'Høj bygning kræver ekstra sikkerhedsforanstaltninger og muligvis stilladsering.'
      });
    }
 
    // Hældning anbefalinger
    if (heightCalculations.pitchAngle > 45) {
      recommendations.push({
        type: 'difficulty',
        title: 'Stejl taghældning',
        message: 'Stejl hældning gør arbejdet mere udfordrende. Planlæg ekstra sikkerhed og tid.'
      });
    }
 
    // Tagtype specifikke anbefalinger
    switch (roofType?.toLowerCase()) {
      case 'betontegl':
        recommendations.push({
          type: 'material',
          title: 'Betontegl vejledning',
          message: 'Betontegl kræver præcis måling af tagcentraler. Bestil 5% ekstra tagsten.'
        });
        break;
      case 'vingetegl':
        recommendations.push({
          type: 'weather',
          title: 'Vingetegl vejrforhold',
          message: 'Vingetegl påvirkes af vejr under installation. Undgå arbejde i kraftig vind eller regn.'
        });
        break;
    }
 
    return recommendations;
  }
 
  /**
   * Hent display navn for tagtype
   */
  getRoofTypeDisplayName(roofType) {
    const displayNames = {
      'betontegl': 'Betontegl',
      'b7': 'B7 Tagplader',
      'b6': 'B6 Tagplader',
      'vingetegl': 'Vingetegl',
      'røde_teglsten': 'Røde Teglsten',
      'fladt_tag': 'Fladt Tag',
      'skraat_tag': 'Skråt Tag',
      'mansard': 'Mansardtag',
      'komplekst': 'Komplekst Tag'
    };
 
    return displayNames[roofType?.toLowerCase()] || roofType;
  }
 
  /**
   * Gem avancerede geometridata
   */
  async saveAdvancedGeometry(projectId, geometryData) {
    try {
      const {
        basicDimensions,
        heightCalculations,
        windboardCalculations,
        materialQuantities,
        svgIllustration
      } = geometryData;
 
      // Gem i hovedgeometri tabel
      await this.db.pool.execute(`
        INSERT INTO roof_geometry (
          project_id, roof_type, total_area, roof_pitch, roof_height,
          length_main, width_main, complexity_factor, estimated_work_hours,
          created_at, updated_at
        ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), NOW())
        ON DUPLICATE KEY UPDATE
        roof_type = VALUES(roof_type),
        total_area = VALUES(total_area),
        roof_pitch = VALUES(roof_pitch),
        roof_height = VALUES(roof_height),
        length_main = VALUES(length_main),
        width_main = VALUES(width_main),
        complexity_factor = VALUES(complexity_factor),
        estimated_work_hours = VALUES(estimated_work_hours),
        updated_at = NOW()
      `, [
        projectId,
        basicDimensions.roofType,
        basicDimensions.baseArea,
        basicDimensions.pitch,
        heightCalculations.ridgeHeight,
        basicDimensions.length,
        basicDimensions.width,
        geometryData.complexity,
        geometryData.estimatedWorkHours
      ]);
 
      // Gem detaljerede data i JSON format
      await this.db.pool.execute(`
        INSERT INTO advanced_geometry_data (
          project_id, height_calculations, windboard_calculations,
          material_quantities, svg_illustration, recommendations,
          created_at
        ) VALUES (?, ?, ?, ?, ?, ?, NOW())
        ON DUPLICATE KEY UPDATE
        height_calculations = VALUES(height_calculations),
        windboard_calculations = VALUES(windboard_calculations),
        material_quantities = VALUES(material_quantities),
        svg_illustration = VALUES(svg_illustration),
        recommendations = VALUES(recommendations),
        updated_at = NOW()
      `, [
        projectId,
        JSON.stringify(heightCalculations),
        JSON.stringify(windboardCalculations),
        JSON.stringify(materialQuantities),
        JSON.stringify(svgIllustration),
        JSON.stringify(geometryData.recommendations)
      ]);
 
      logger.info('Advanced geometry data saved', {
        projectId,
        roofType: basicDimensions.roofType,
        area: basicDimensions.baseArea
      });
 
      return { success: true };
    } catch (error) {
      logger.error('Error saving advanced geometry:', error);
      throw error;
    }
  }
}
 
module.exports = AdvancedGeometryService;