from pathlib import Path

from app.config import settings
from app.services.d2l import D2LService
from app.services.store import JsonStore


def main() -> None:
    Path(settings.upload_tmp_dir).mkdir(parents=True, exist_ok=True)
    Path(settings.state_dir).mkdir(parents=True, exist_ok=True)
    store = JsonStore()
    for name, default in {
        'courses': [],
        'assignments': [],
        'submissions': [],
        'recordings': [],
        'sync_runs': [],
    }.items():
        path = Path(settings.state_dir) / f'{name}.json'
        if not path.exists():
            store.save(name, default)
    result = D2LService().sync_to_store()
    print(result)


if __name__ == '__main__':
    main()
