# Path: pycounter/sushi.py
# NS = pycounter.constants.NS
# def get_sushi_stats_raw(
#     wsdl_url,
#     start_date,
#     end_date,
#     requestor_id=None,
#     requestor_email=None,
#     requestor_name=None,
#     customer_reference=None,
#     customer_name=None,
#     report="JR1",
#     release=4,
#     sushi_dump=False,
#     verify=True,
#     **extra_params,
# ):
# def get_status(url: str, release: int) -> str:
# def get_report(*args, **kwargs):
# def ns(namespace, name):
# def raw_to_full(raw_report):
# 
# Path: pycounter/helpers.py
# def convert_date_run(datestring):
#     """
#     Convert a date of the format 'YYYY-MM-DD' to a datetime.date object.
# 
#     (Will also accept MM/DD/YYYY format, ISO 8601 timestamps, or existing
#     datetime objects; these shouldn't be in COUNTER reports, but they
#     do show up in real world data...)
# 
#     :param datestring: the string to convert to a date.
# 
#     :return: datetime.date object
# 
#     """
#     if isinstance(datestring, datetime.date):
#         return datestring
# 
#     return pendulum.parse(datestring, strict=False).date()
# 
# def last_day(orig_date):
#     """
#     Find last day of a month from any day in the month.
# 
#     :param orig_date: the date within the month for which we want the
#         last day as datetime.date
# 
#     :return: datetime.date of last day of the month
# 
#     """
#     day_number = calendar.monthrange(orig_date.year, orig_date.month)[1]
#     return datetime.date(orig_date.year, orig_date.month, day_number)
# 
# def prev_month(dateobj):
#     """Find the first day of the previous month before the given date.
# 
#     :param dateobj: the date within the month for which we want the
#         previous month's first day as datetime.date.
# 
#     :return: datetime.date of first day of the previous month.
# 
#     """
#     year_delta, old_month = divmod(dateobj.month - 2, 12)
#     return datetime.date(dateobj.year + year_delta, old_month + 1, 1)


import datetime
import logging
import sys
import click
from pycounter import sushi
from pycounter.helpers import convert_date_run, last_day, prev_month
    format_,
    output_file,
    dump,
    no_ssl_verify,
    no_delay,
    status,
):
    """Main function for the SUSHI client."""
    # pylint: disable=too-many-locals
    if dump:
        logging.basicConfig(level=logging.DEBUG)
    else:
        logging.basicConfig()
    if status:
        status_response = sushi.get_status(url, release)
        click.echo(status_response)
        sys.exit(0)
    click.echo(f"pycounter SUSHI client for URL {url} ({report} R{release})")
    if end_date is not None and start_date is None:
        click.echo("Cannot specify --end_date without --start_date", err=True)
        sys.exit(1)
    if start_date is None:
        converted_start_date = prev_month(datetime.datetime.now())
    else:
        converted_start_date = convert_date_run(start_date)
    if end_date is None:
        converted_end_date = last_day(converted_start_date)
    else:
        converted_end_date = convert_date_run(end_date)


# Path: pycounter/sushi.py
# NS = pycounter.constants.NS
# def get_sushi_stats_raw(
#     wsdl_url,
#     start_date,
#     end_date,
#     requestor_id=None,
#     requestor_email=None,
#     requestor_name=None,
#     customer_reference=None,
#     customer_name=None,
#     report="JR1",
#     release=4,
#     sushi_dump=False,
#     verify=True,
#     **extra_params,
# ):
# def get_status(url: str, release: int) -> str:
# def get_report(*args, **kwargs):
# def ns(namespace, name):
# def raw_to_full(raw_report):
# 
# Path: pycounter/helpers.py
# def convert_date_run(datestring):
#     """
#     Convert a date of the format 'YYYY-MM-DD' to a datetime.date object.
# 
#     (Will also accept MM/DD/YYYY format, ISO 8601 timestamps, or existing
#     datetime objects; these shouldn't be in COUNTER reports, but they
#     do show up in real world data...)
# 
#     :param datestring: the string to convert to a date.
# 
#     :return: datetime.date object
# 
#     """
#     if isinstance(datestring, datetime.date):
#         return datestring
# 
#     return pendulum.parse(datestring, strict=False).date()
# 
# def last_day(orig_date):
#     """
#     Find last day of a month from any day in the month.
# 
#     :param orig_date: the date within the month for which we want the
#         last day as datetime.date
# 
#     :return: datetime.date of last day of the month
# 
#     """
#     day_number = calendar.monthrange(orig_date.year, orig_date.month)[1]
#     return datetime.date(orig_date.year, orig_date.month, day_number)
# 
# def prev_month(dateobj):
#     """Find the first day of the previous month before the given date.
# 
#     :param dateobj: the date within the month for which we want the
#         previous month's first day as datetime.date.
# 
#     :return: datetime.date of first day of the previous month.
# 
#     """
#     year_delta, old_month = divmod(dateobj.month - 2, 12)
#     return datetime.date(dateobj.year + year_delta, old_month + 1, 1)


# Path: pycounter/sushiclient.py
import datetime
import logging
import sys
import click
from pycounter import sushi
from pycounter.helpers import convert_date_run, last_day, prev_month

    format_,
    output_file,
    dump,
    no_ssl_verify,
    no_delay,
    status,
):
    """Main function for the SUSHI client."""
    # pylint: disable=too-many-locals
    if dump:
        logging.basicConfig(level=logging.DEBUG)
    else:
        logging.basicConfig()
    if status:
        status_response = sushi.get_status(url, release)
        click.echo(status_response)
        sys.exit(0)
    click.echo(f"pycounter SUSHI client for URL {url} ({report} R{release})")
    if end_date is not None and start_date is None:
        click.echo("Cannot specify --end_date without --start_date", err=True)
        sys.exit(1)
    if start_date is None:
        converted_start_date = prev_month(datetime.datetime.now())
    else:
        converted_start_date = convert_date_run(start_date)
    if end_date is None:
        converted_end_date = last_day(converted_start_date)
    else:
        converted_end_date = convert_date_run(end_date)


    report = sushi.get_report(