"""Test script for Zernike WFE insight with OPD method."""
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent.parent))

from optimization_engine.insights.zernike_wfe import ZernikeWFEInsight
from optimization_engine.insights.base import InsightConfig

study = Path('studies/M1_Mirror/m1_mirror_cost_reduction_V9')
insight = ZernikeWFEInsight(study)

if insight.can_generate():
    print('Insight can be generated!')
    print(f'OP2: {insight.op2_path}')
    print(f'Geo: {insight.geo_path}')
    config = InsightConfig()
    result = insight.generate(config)
    if result.success:
        n_files = len(result.summary.get('html_files', []))
        print(f'Success! Generated {n_files} files')
        for f in result.summary.get('html_files', []):
            print(f'  - {Path(f).name}')
        print()
        print('Summary:')
        for k, v in result.summary.items():
            if k != 'html_files':
                print(f'  {k}: {v}')
    else:
        print(f'Failed: {result.error}')
else:
    print('Cannot generate insight')
