# encoding: utf-8

from utils import get_pos_list
from reportsdata.salechallengereport import SaleChallengeGenerator, SaleChallengePresenter
from salechallengereport.repository import SaleChallengeRepository, OrderRepository, ProductRepository


class ReportGenerator(object):

    @staticmethod
    def generate(mb_context, _, operator_id, sale_challenge_id):
        operator_id = str(int(0 if operator_id in (None, 'None') else operator_id))
        if operator_id == '0':
            operator_id = None

        order_repository = OrderRepository(mb_context, get_pos_list(mb_context))
        sale_challenge_repository = SaleChallengeRepository(mb_context)
        product_repository = ProductRepository(mb_context)

        generator = SaleChallengeGenerator(
                order_repository,
                product_repository,
                sale_challenge_repository,
                sale_challenge_id,
                operator_id
        )
        presenter = SaleChallengePresenter(38)

        return generator, presenter

