# Path: oscar_mws/feeds/gateway.py
# OP_TYPE_UPDATE = 'Update'
# OP_TYPE_PARTIAL_UPDATE = 'PartialUpdate'
# OP_TYPE_DELETE = 'Delete'
# class MwsFeedError(BaseException):
# def handle_feed_submission_response(merchant, response, feed_xml=None):
# def submit_product_feed(products, marketplaces, dry_run=False,
#                         operation_type=OP_TYPE_UPDATE):
# def update_feed_submission(submission):
# def update_feed_submissions(merchant):
# def list_submitted_feeds(merchants=None):
# def cancel_submission(submission):
# def process_submission_results(submission):
# def update_product_identifiers(merchant, products):
# def switch_product_fulfillment(marketplace, products, dry_run=False):


from optparse import make_option
from django.db.models import get_model
from django.core.management.base import NoArgsCommand, CommandError
from oscar_mws.feeds import gateway


class Command(NoArgsCommand):
    option_list = NoArgsCommand.option_list + (
        make_option(
            '--list',
            action='store_true',
            dest='list_feeds',
            default=False,
            help=('List all feed from Amazon including type and status.')
        ),
        make_option(
            '--submission',
            dest='submission_id',
            help=('Submission ID to retrieve details results for.')
        ),
    )

    def handle_noargs(self, **options):
        if options.get('list_feeds'):
            for feed in gateway.list_submitted_feeds():
                print "{0}\t\t{1}\t\t{2}".format(
                    feed['submission_id'],
                    feed['feed_type'],
                    feed['status'],
                )
            return

        submission_id = options.get('submission_id')
        if submission_id:

# Path: oscar_mws/feeds/gateway.py
# OP_TYPE_UPDATE = 'Update'
# OP_TYPE_PARTIAL_UPDATE = 'PartialUpdate'
# OP_TYPE_DELETE = 'Delete'
# class MwsFeedError(BaseException):
# def handle_feed_submission_response(merchant, response, feed_xml=None):
# def submit_product_feed(products, marketplaces, dry_run=False,
#                         operation_type=OP_TYPE_UPDATE):
# def update_feed_submission(submission):
# def update_feed_submissions(merchant):
# def list_submitted_feeds(merchants=None):
# def cancel_submission(submission):
# def process_submission_results(submission):
# def update_product_identifiers(merchant, products):
# def switch_product_fulfillment(marketplace, products, dry_run=False):


# Path: oscar_mws/management/commands/mws_feed_results.py
from optparse import make_option
from django.db.models import get_model
from django.core.management.base import NoArgsCommand, CommandError
from oscar_mws.feeds import gateway



class Command(NoArgsCommand):
    option_list = NoArgsCommand.option_list + (
        make_option(
            '--list',
            action='store_true',
            dest='list_feeds',
            default=False,
            help=('List all feed from Amazon including type and status.')
        ),
        make_option(
            '--submission',
            dest='submission_id',
            help=('Submission ID to retrieve details results for.')
        ),
    )

    def handle_noargs(self, **options):
        if options.get('list_feeds'):
            for feed in gateway.list_submitted_feeds():
                print "{0}\t\t{1}\t\t{2}".format(
                    feed['submission_id'],
                    feed['feed_type'],
                    feed['status'],
                )
            return

        submission_id = options.get('submission_id')
        if submission_id:

            submission = gateway.update_feed_submission(submission_id)