from pathlib import Path
import hashlib,json,os,shutil

project=Path('/Users/vengurnagu/Documents/ChatGPT/Nagarajan - Sense India')
visuals=Path('/Users/vengurnagu/.codex/visualizations/2026/10/22/01a16312-5ae9-7d31-8ff9-c9cf965dca86')
destination=Path('/Users/vengurnagu/Desktop/Sense India')
references=Path('/Users/vengurnagu/Downloads/SenseIndia')

def inventory(folder):
    result={}
    for current,dirs,files in os.walk(folder,followlinks=False):
        for name in list(dirs):
            p=Path(current)/name
            if p.is_symlink():
                result[str(p.relative_to(folder))]={'link':os.readlink(p)}
                dirs.remove(name)
        for name in files:
            p=Path(current)/name
            if p.is_symlink(): result[str(p.relative_to(folder))]={'link':os.readlink(p)}
            else:
                h=hashlib.sha256()
                with p.open('rb') as f:
                    for chunk in iter(lambda:f.read(1024*1024),b''):h.update(chunk)
                result[str(p.relative_to(folder))]={'bytes':p.stat().st_size,'sha256':h.hexdigest()}
    return result

assert project.is_dir() and not project.is_symlink(),'Project already moved or unavailable'
assert visuals.is_dir() and not visuals.is_symlink(),'Visual source folder already moved or unavailable'
assert destination.is_dir() and not any(destination.iterdir()),'Destination must still be empty'
original=inventory(project);original_visuals=inventory(visuals)

# Move physical files without overwriting anything at the destination.
for p in list(project.iterdir()):shutil.move(str(p),str(destination/p.name))
project.rmdir();project.symlink_to(destination,target_is_directory=True)
visual_target=destination/'visualizations'
shutil.move(str(visuals),str(visual_target))
visuals.symlink_to(visual_target,target_is_directory=True)

# Keep original supplied documents in Downloads and include project-local copies.
shutil.copytree(references,destination/'reference-documents',symlinks=True)

# Preserve the task-specific helpers and source-page previews created in temporary storage.
support=destination/'working-support';support.mkdir()
temp_root=Path('/private/tmp')
patterns=['enrolment-pages.js','screening-pages.js','iep-pages.js','sense-survey-*.png','sense-enrolment-*.png','pfp-*.png','passport-*.png','quarterly-*.png']
for pattern in patterns:
    for p in temp_root.glob(pattern):
        if p.is_file():shutil.copy2(p,support/p.name)

after=inventory(destination)
assert all(after.get(name)==entry for name,entry in original.items()),'Project integrity verification failed'
assert inventory(visual_target)==original_visuals,'Visualization integrity verification failed'
assert inventory(references)==inventory(destination/'reference-documents'),'Reference integrity verification failed'

links=[]
for p in sorted((destination/'output'/'mockups').glob('*.html')):
    links.append(f'<li><a href="output/mockups/{p.name}">{p.stem.replace("-"," ").title()}</a></li>')
pdfs=[]
for p in sorted((destination/'output'/'pdf').glob('*.pdf')):
    pdfs.append(f'<li><a href="output/pdf/{p.name}">{p.name}</a></li>')
index='''<!doctype html><html lang="en"><meta charset="utf-8"><title>Sense India Project</title>
<style>body{font:16px/1.6 system-ui;max-width:960px;margin:40px auto;padding:0 24px;color:#47224f}h1{border-bottom:4px solid #f37933;padding-bottom:12px}a{color:#47224f}li{margin:8px 0}</style>
<h1>Sense India Project</h1><p>Interactive mockups, PDFs, source documents and working files. All demos use fictional data.</p>
<h2>Interactive mockups</h2><ul>'''+''.join(links)+'''</ul><h2>PDFs</h2><ul>'''+''.join(pdfs)+'''</ul>
<h2>Other project materials</h2><ul><li><a href="outputs/sense-india/">Roles and modules spreadsheets</a></li><li><a href="reference-documents/">Supplied documents and logo</a></li><li><a href="work/">Working files</a></li><li><a href="tmp/">Scripts, verification files and previews</a></li><li><a href="visualizations/">Editable interactive source files</a></li></ul></html>'''
(destination/'START_HERE.html').write_text(index)
(destination/'README.md').write_text('''# Sense India project

Open START_HERE.html for links to the interactive mockups and PDFs.

- output/: interactive deliverables, PDFs, plans and ZIP bundles
- outputs/: roles and modules spreadsheets
- visualizations/: editable inline mockup sources
- reference-documents/: copies of the supplied documents and logo
- work/: project builders and supporting files
- tmp/: authoring scripts, verification files and rendered previews
- working-support/: supporting files recovered from temporary storage

Moved to Desktop/Sense India on 24 October 2026. The previous project and visualization paths are symbolic links to this folder, preserving earlier local links and script references. Original supplied documents remain in Downloads/SenseIndia.
''')
(destination/'MOVE_VERIFICATION.json').write_text(json.dumps({'date':'2026-10-24','destination':str(destination),'project_files_verified':len(original),'visualization_files_verified':len(original_visuals),'reference_files_verified':len(inventory(references)),'original_project_shortcut':str(project),'original_visualization_shortcut':str(visuals),'project_manifest':original,'visualization_manifest':original_visuals},indent=2))
print(json.dumps({'destination':str(destination),'project_files_verified':len(original),'visualizations_verified':len(original_visuals),'reference_files_verified':len(inventory(references)),'interactive_demos':len(links),'pdfs':len(pdfs),'old_links_preserved':project.resolve()==destination and visuals.resolve()==visual_target}))
