from pathlib import Path
import shutil

ROOT = Path(__file__).resolve().parent / "property-pages"
GROUPS = {
    "01-business-planning-and-development": ["0001-", "0002-", "0006-", "0010-", "0015-"],
    "02-investment-strategy-and-ownership": ["0003-", "0005-", "0008-", "0011-", "0017-", "0025-"],
    "03-rooming-houses-and-multi-occupancy": ["0016-", "0024-", "0035-", "0036-", "0038-", "0039-", "0040-", "0041-"],
    "04-rent-to-rent-and-coliving": ["0018-", "0020-", "0021-", "0022-"],
    "05-commercial-leasing": ["0023-", "0037-"],
    "06-property-management-operations": ["0009-", "0013-", "0014-"],
    "07-business-models-and-trends": ["0004-", "0007-", "0012-"],
}

for folder, prefixes in GROUPS.items():
    destination = ROOT / folder / "sources"
    destination.mkdir(parents=True, exist_ok=True)
    for prefix in prefixes:
        matches = list(ROOT.glob(prefix + "*.md"))
        if len(matches) != 1:
            raise RuntimeError(f"Expected one match for {prefix}, found {len(matches)}")
        shutil.move(str(matches[0]), destination / matches[0].name)
