# Path: cap_client/api/repositories_api.py
# class RepositoriesAPI(CapAPI):
#     """Interface for CAP repositories/webhooks methods."""
# 
#     def get(self, pid, with_snapshots=False):
#         """Get list of repositories attached to analysis with given PID.
# 
#         :param pid: analysis PID
#         :type pid: str
#         :param with_snapshots: include snapshots informations
#         :type with_snapshots: bool
#         :return: list of repositories
#         :rtype: list
#         """
#         response = self._make_request(
#             url=urljoin('deposits/', pid),
#             headers={'Accept': 'application/repositories+json'},
#         )
# 
#         if not with_snapshots:
#             for hook in response['webhooks']:
#                 hook.pop('snapshots')
# 
#         return response['webhooks']
# 
#     def upload(self, pid, url, event_type=None):
#         """Get list of repositories attached to analysis with given PID.
# 
#         :param pid: analysis PID
#         :type pid: str
#         :param event_type: create webhook on this event
#         :type event_type: str, optional
#         :return: None
#         """
#         self._make_request(url='deposits/{}/actions/upload'.format(pid),
#                            expected_status_code=201,
#                            method='post',
#                            headers={
#                                'Content-Type': 'application/json',
#                                'Accept': 'application/repositories+json'},
#                            data=json.dumps({
#                                'url': url,
#                                'webhook': True if event_type else False,
#                                'event_type': event_type
#                            }))
# 
# Path: cap_client/utils.py
# class ColoredGroup(HelpColorsGroup):
# class NotRequiredIf(click.Option):
# class MultipleMutuallyExclusiveOptions(click.Option):
#     def __init__(self, *args, **kwargs):
# def make_tarfile(output_filename, source_dir):
# def validate_version(ctx, param, version_value):
# def load_json_from_file(ctx, param, value):
# def load_json(ctx, param, value):
#     def __init__(self, *args, **kwargs):
#     def handle_parse_result(self, ctx, opts, args):
#     def __init__(self, *args, **kwargs):
#     def handle_parse_result(self, ctx, opts, args):
# def logger(fun):
#     def wrapper(*args, **kwargs):
# def pid_option(required):
#     def inner_pid_option(fun):
#         def wrapper(*args, **kwargs):


import click
from cap_client.api import RepositoriesAPI
from cap_client.utils import ColoredGroup, json_dumps, logger, pid_option
)
@pass_api
@logger
def get(api, pid, with_snapshots):
    """Get all repositories connected with your analysis."""
    res = api.get(
        pid=pid,
        with_snapshots=with_snapshots,
    )

    click.echo(json_dumps(res))


@repositories.command()
@pid_option(required=True)
@click.argument('url')
@pass_api
@logger
def upload(api, pid, url):
    """Upload repository tarball to your analysis."""
    api.upload(
        pid=pid,
        url=url,
    )

    click.echo('Repository tarball was saved with your analysis files. '
               '(access using `cap-client files` methods)')


@repositories.command()

# Path: cap_client/api/repositories_api.py
# class RepositoriesAPI(CapAPI):
#     """Interface for CAP repositories/webhooks methods."""
# 
#     def get(self, pid, with_snapshots=False):
#         """Get list of repositories attached to analysis with given PID.
# 
#         :param pid: analysis PID
#         :type pid: str
#         :param with_snapshots: include snapshots informations
#         :type with_snapshots: bool
#         :return: list of repositories
#         :rtype: list
#         """
#         response = self._make_request(
#             url=urljoin('deposits/', pid),
#             headers={'Accept': 'application/repositories+json'},
#         )
# 
#         if not with_snapshots:
#             for hook in response['webhooks']:
#                 hook.pop('snapshots')
# 
#         return response['webhooks']
# 
#     def upload(self, pid, url, event_type=None):
#         """Get list of repositories attached to analysis with given PID.
# 
#         :param pid: analysis PID
#         :type pid: str
#         :param event_type: create webhook on this event
#         :type event_type: str, optional
#         :return: None
#         """
#         self._make_request(url='deposits/{}/actions/upload'.format(pid),
#                            expected_status_code=201,
#                            method='post',
#                            headers={
#                                'Content-Type': 'application/json',
#                                'Accept': 'application/repositories+json'},
#                            data=json.dumps({
#                                'url': url,
#                                'webhook': True if event_type else False,
#                                'event_type': event_type
#                            }))
# 
# Path: cap_client/utils.py
# class ColoredGroup(HelpColorsGroup):
# class NotRequiredIf(click.Option):
# class MultipleMutuallyExclusiveOptions(click.Option):
#     def __init__(self, *args, **kwargs):
# def make_tarfile(output_filename, source_dir):
# def validate_version(ctx, param, version_value):
# def load_json_from_file(ctx, param, value):
# def load_json(ctx, param, value):
#     def __init__(self, *args, **kwargs):
#     def handle_parse_result(self, ctx, opts, args):
#     def __init__(self, *args, **kwargs):
#     def handle_parse_result(self, ctx, opts, args):
# def logger(fun):
#     def wrapper(*args, **kwargs):
# def pid_option(required):
#     def inner_pid_option(fun):
#         def wrapper(*args, **kwargs):


# Path: cap_client/cli/repositories_cli.py
import click
from cap_client.api import RepositoriesAPI
from cap_client.utils import ColoredGroup, json_dumps, logger, pid_option

)
@pass_api
@logger
def get(api, pid, with_snapshots):
    """Get all repositories connected with your analysis."""
    res = api.get(
        pid=pid,
        with_snapshots=with_snapshots,
    )

    click.echo(json_dumps(res))


@repositories.command()
@pid_option(required=True)
@click.argument('url')
@pass_api
@logger
def upload(api, pid, url):
    """Upload repository tarball to your analysis."""
    api.upload(
        pid=pid,
        url=url,
    )

    click.echo('Repository tarball was saved with your analysis files. '
               '(access using `cap-client files` methods)')


@repositories.command()

@pid_option(required=True)