"""
    These are the sub-commands for a top level object added to the CLI group in 'cli.py'.
    The commands and options are implemented here and the logic behind them resides in the corresponding behavior file.
"""

from cli import pyke, behavior
import click

@click.group(help='Experience related commands.')
def experience():
  pass

@click.command('ls', help="List the experiences related to the selected profile.")
@click.option('--profile', '-p', prompt=True, help='The name of the profile to use as the context for the command.', autocompletion=pyke.auth.get_profile_names)
@click.option('--format', '-f', default='{id} {label} {name} {createdAt}', help='The --format option takes the column name of the returned table wrapped in \
{} and returns only that column. It is not compatible with --json flag.')
@click.option('--filter', default='')
@click.option('--page', default=1)
@click.option('--pagesize', default=100)
@click.option('--json', is_flag=True, help='Return raw json from the platform.')
@pyke.auth.profile_context_required
def list(**kwargs):
  behavior.ExperienceBehavior(**kwargs).list()

@click.command('export', help='Exports an experience as a JSON file')
@click.option('--profile', '-p', prompt=True, help='The name of the profile to use as the context for the command.', autocompletion=pyke.auth.get_profile_names)
@click.option('--label', '-l', help='The label of the experience being exported. This is the experience "Name" in the UI.')
@click.option('--name', '-n', default='', help='The autogenerated name (aka namespace) of the experience being exported. This is not the experience "Name" in the UI.')
@click.option('--export-file', '-path', help='The location to save the export file. Not supported if --json is specified.')
@click.option('--json', is_flag=True, help='Return raw json from the platform')
@pyke.auth.profile_context_required
def export(**kwargs):
  behavior.ExperienceBehavior(**kwargs).export()

@click.command('import', help='Imports an experience via a JSON file')
@click.option('--profile', '-p', prompt=True, help='The name of the profile to use as the context for the command.', autocompletion=pyke.auth.get_profile_names)
@click.option('--label', '-l', prompt=True, help='The label for the new experience. This aligns with "Name" in the UI.')
@click.option('--description', '-d', help='The description for the new experience')
@click.option('--collection-id', '-ci', default='', help='The experience collection ID for the new experience')
@click.option('--device', default=None, help='The preview device the experience is displayed in while in the studio')
@click.option('--collection-name', '-cn', help='The experience collection name for the new experience')
@click.option('--activation-code', '-ac', prompt=True, help='The activation code for the new experience')
@click.option('--template', '-t', is_flag=True, help='Indicates the new experience should be a template')
@click.option('--redirect-url', '-ru', default='', help='The redirect url for the new experience')
@click.option('--import-file', '-path', prompt=True, help='The location of the experience file to import')
@click.option('--json', is_flag=True, help='Return raw json from the platform')
@pyke.auth.profile_context_required
def import_(**kwargs):
  behavior.ExperienceBehavior(**kwargs).import_()

experience.add_command(list)
experience.add_command(export)
experience.add_command(import_)
