# AUTOGENERATED! DO NOT EDIT! File to edit: ../../../../../../../../../Users/lukastk/dev/2025-11-09_00__repoyard/pts/mod/cmds/02_sync_repo.pct.py.

# %% top_export
from pathlib import Path

from repoyard._utils.bisync_helper import bisync_helper, SyncSetting
from repoyard.config import get_config, StorageType
from repoyard import const

def sync_repo(
    config_path: Path,
    repo_full_name: str,
    sync_setting: SyncSetting = SyncSetting.BISYNC,
    force: bool = False,
):
    """
    Syncs a repo with its remote.
    
    Args:
        config_path: Path to the repoyard config file.
        repo_full_name: Name of the repo to sync.
        sync_setting: The sync setting to use.
        force: If True, the sync will be forced. Used in the case 
    """
    
    # AUTOGENERATED! DO NOT EDIT! File to edit: ../../../../../../../../../Users/lukastk/dev/2025-11-09_00__repoyard/pts/mod/cmds/02_sync_repo.pct.py.
    
    # %% auto 0
    __all__ = ['config', 'repoyard_meta', 'repo_meta']
    
    # %% ../../../../../../../../../Users/lukastk/dev/2025-11-09_00__repoyard/pts/mod/cmds/02_sync_repo.pct.py 13
    config = get_config(config_path)
    
    # %% ../../../../../../../../../Users/lukastk/dev/2025-11-09_00__repoyard/pts/mod/cmds/02_sync_repo.pct.py 16
    from .._repos import get_repoyard_meta
    repoyard_meta = get_repoyard_meta(config)
    
    if repo_full_name not in repoyard_meta.by_full_name:
        raise ValueError(f"Repo '{repo_full_name}' not found.")
    
    repo_meta = repoyard_meta.by_full_name[repo_full_name]
    
    # %% ../../../../../../../../../Users/lukastk/dev/2025-11-09_00__repoyard/pts/mod/cmds/02_sync_repo.pct.py 18
    if repo_meta.get_storage_location_config(config).storage_type == StorageType.LOCAL:
        pass
        return #|return_line
    
    # %% ../../../../../../../../../Users/lukastk/dev/2025-11-09_00__repoyard/pts/mod/cmds/02_sync_repo.pct.py 20
    bisync_helper(
        rclone_config_path=config.rclone_config_path,
        sync_setting=sync_setting,
        local_path=repo_meta.get_local_path(config),
        remote=repo_meta.storage_location,
        remote_path=repo_meta.get_remote_path(config),
        force=force,
        include=[f"/{const.REPO_METAFILE_REL_PATH}"]
    )
    
    # %% ../../../../../../../../../Users/lukastk/dev/2025-11-09_00__repoyard/pts/mod/cmds/02_sync_repo.pct.py 23
    bisync_helper(
        rclone_config_path=config.rclone_config_path,
        sync_setting=sync_setting,
        local_path=repo_meta.get_local_repoconf_path(config),
        remote=repo_meta.storage_location,
        remote_path=repo_meta.get_remote_repoconf_path(config),
        force=force,
    )
    
    # %% ../../../../../../../../../Users/lukastk/dev/2025-11-09_00__repoyard/pts/mod/cmds/02_sync_repo.pct.py 26
    _repoyard_include_path = repo_meta.get_local_repoconf_path(config) / ".repoyard_include"
    _repoyard_exclude_path = repo_meta.get_local_repoconf_path(config) / ".repoyard_exclude"
    _repoyard_filters_path = repo_meta.get_local_repoconf_path(config) / ".repoyard_filters"
    
    _repoyard_include_path = _repoyard_include_path if _repoyard_include_path.exists() else None
    _repoyard_exclude_path = _repoyard_exclude_path if _repoyard_exclude_path.exists() else None
    _repoyard_filters_path = _repoyard_filters_path if _repoyard_filters_path.exists() else None
    
    # %% ../../../../../../../../../Users/lukastk/dev/2025-11-09_00__repoyard/pts/mod/cmds/02_sync_repo.pct.py 28
    bisync_helper(
        rclone_config_path=config.rclone_config_path,
        sync_setting=sync_setting,
        local_path=repo_meta.get_local_repodata_path(config),
        remote=repo_meta.storage_location,
        remote_path=repo_meta.get_remote_repodata_path(config),
        force=force,
        include_path=_repoyard_include_path,
        exclude_path=_repoyard_exclude_path,
        filters_path=_repoyard_filters_path,
    )
    
    # %% ../../../../../../../../../Users/lukastk/dev/2025-11-09_00__repoyard/pts/mod/cmds/02_sync_repo.pct.py 30
    from .._repos import refresh_repoyard_meta
    refresh_repoyard_meta(config)