#!/usr/bin/env python3
from __future__ import annotations

import os
import shutil
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]
SOURCE_ROOT = Path(os.environ.get('TOTALLY_SPIES_SOURCE_ROOT', '/home/mnm/sync/totally-spies/laurent_whatsapp_totally_spies'))
SESSION_ROOT = Path(os.environ.get('TOTALLY_SPIES_SESSION_ROOT', '/home/mnm/.copilot/session-state/dc10e698-98fe-4855-ac2a-89d7b4b2721f'))
RADIAL_ROOT = Path(os.environ.get('CULTSHOT_RADIAL_ROOT', '/home/mnm/workspaces/cultshot-radial'))


def ensure_exists(path: Path) -> None:
    if not path.exists():
        raise FileNotFoundError(path)


def copy_file(src: Path, dst: Path) -> None:
    ensure_exists(src)
    dst.parent.mkdir(parents=True, exist_ok=True)
    shutil.copy2(src, dst)


def replace_tree(src: Path, dst: Path) -> None:
    ensure_exists(src)
    if dst.exists():
        shutil.rmtree(dst)
    shutil.copytree(src, dst)


def main() -> None:
    files = [
        (SOURCE_ROOT / 'details.txt', ROOT / 'materials/source-context/details.txt'),
        (SOURCE_ROOT / 'relevant_excerpt.txt', ROOT / 'materials/source-context/relevant_excerpt.txt'),
        (SOURCE_ROOT / '2026-03-16_context-image.jpg', ROOT / 'materials/source-context/2026-03-16_context-image.jpg'),
        (SOURCE_ROOT / '2026-03-26_test-video.mp4', ROOT / 'materials/source-media/2026-03-26_test-video.mp4'),
        (SESSION_ROOT / 'plan.md', ROOT / 'docs/internal/session-plan.md'),
    ]
    trees = [
        (SESSION_ROOT / 'files/video-review-test', ROOT / 'materials/benchmark/march-26'),
        (SESSION_ROOT / 'checkpoints', ROOT / 'docs/internal/checkpoints'),
        (RADIAL_ROOT / 'docs', ROOT / 'materials/reference/cultshot-radial/docs'),
    ]

    for src, dst in files:
        copy_file(src, dst)
    for src, dst in trees:
        replace_tree(src, dst)

    print('Synced copied materials into repo.')


if __name__ == '__main__':
    main()
