# Reproduce the finite sample corpus and its actual-geometry validation manifest.
import argparse
import importlib
import json
from pathlib import Path

from hearthwright import Building, generate

CLIENTS = (
    'mediterranean_villa',
    'merchant_manor',
    'red_roof_farmstead',
    'root_house',
    'sandstone_cottage',
    'stilt_water_cabin',
    'stilted_manor',
    'stone_cottage',
    'canal_apothecary',
    'woodland_archive',
    'orchard_house',
    'hillside_studio',
    'courtyard_house',
)


def main():
    """Generate only a finite declared corpus, never enumerate parameter products."""
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('--seeds', type=int, nargs='+', default=[0, 1])
    parser.add_argument('--output-dir', type=Path, default=Path('samples'))
    args = parser.parse_args()
    records = []
    for client in CLIENTS:
        design = importlib.import_module('examples.' + client).DESIGN
        for seed in args.seeds:
            building = generate(design, seed)
            path = args.output_dir / f'{client}-{seed}.litematic'
            building.export(path)
            roundtrip = building.verify(path)
            report = Building.load(path).validate().require_valid()
            records.append({'client': f'examples/{client}.py', 'seed': seed, 'schematic': path.name, 'metadata': path.with_suffix('.json').name, 'resolved': building.plan.summary(), 'structural_signature': building.metadata['structural_signature'], 'geometry_signature': building.metadata['geometry_signature'], 'validation': report.to_dict(), 'roundtrip': roundtrip})
            print(f'{client} seed={seed}: {roundtrip["blocks"]} blocks, validated after reload', flush=True)
    manifest = {'schema': 1, 'command': 'python -m scripts.sample_batch', 'samples': records, 'observed_structures': len({r['structural_signature'] for r in records}), 'observed_geometry_signatures': len({r['geometry_signature'] for r in records})}
    args.output_dir.mkdir(parents=True, exist_ok=True)
    (args.output_dir / 'manifest.json').write_text(json.dumps(manifest, indent=2, sort_keys=True) + '\n')


if __name__ == '__main__':
    main()
