"""This module holds the command to test the SABA client on CLI"""

from django.core.management.base import BaseCommand, CommandError

from mtp.apps.assessments.models.certifications import CertificationProgramUserStatus
from mtp.discrete_apps.saba.tasks import AssessmentsResultsToSabaTask


class Command(BaseCommand):
    """Launch an assessment results sync to Saba"""

    help = 'Launch an assessment results sync to Saba'

    def add_arguments(self, parser):
        """Add arguments to the task

        For the parameters, see ``django.core.management.base.BaseCommand``"""

        parser.add_argument(
            'certification_id',
            # nargs='+',
            help='Id of the ``CertificationProgramUserStatus`` to send to Saba'
        )

    def handle(self, *args, **options):  # pylint: disable=unused-argument
        """Execute the command with the provided arguments

        For the parameters, see ``django.core.management.base.BaseCommand``"""

        try:
            certification = CertificationProgramUserStatus.objects.get(
                pk=options['certification_id']
            )
        except CertificationProgramUserStatus.DoesNotExist:
            raise CommandError('No such ``CertificationProgramUserStatus``.')

        task = AssessmentsResultsToSabaTask()
        task.run(
            certification=certification
        )
