# encoding: utf-8
import json

from benefitsreport.repository import BenefitsOrderRepository
from reportsdata.benefitsreport import BenefitsGenerator, BenefitsPresenter


class ReportGenerator(object):
    @staticmethod
    def generate(mb_context, _, *args):

        initial_date = args[4]
        end_date = args[5]
        operator_id = None if args[6] == '0' else args[6]
        benefits = json.loads(args[8])
        pos_list = json.loads(args[len(args) - 1])
        order_repository = BenefitsOrderRepository(mb_context, pos_list)
        generator = BenefitsGenerator(order_repository, initial_date, end_date, operator_id, benefits)
        presenter = BenefitsPresenter(38)

        return generator, presenter

