# encoding: utf-8
import json

from typing import (
    Any,
    Optional
)

from hourlysalesreport import HourlySalesReport
from hourlysalesreport.repository import OrderRepository as HourlySalesOrderRepository


class ReportGenerator(object):
    @staticmethod
    def generate(
        mb_context,                     # type: Any
        pos_id,                         # type: str
        pos_list,                       # type: str
        operator_id,                    # type: str
        period,                         # type: str
        by_created_order_time=False     # type: Optional[bool]
    ):
        # type: (...) -> str

        pos_list = json.loads(pos_list)
        hourly_sales_report_generator = HourlySalesReport(
            order_repository=HourlySalesOrderRepository(
                mb_context=mb_context,
                pos_list=pos_list
            ),
            by_created_order_time=by_created_order_time
        )

        return hourly_sales_report_generator.generate_hourly_sales_report(
            pos_id=pos_id,
            user_id=operator_id,
            period=period
        )
