# encoding: utf-8

from justificationdiscountreport import JustificationDiscountReport
from justificationdiscountreport.repository import JustificationDiscountRepository
from report import Generator
from reportsdata.justificationdiscountreport.dto import (
    JustificationDiscountBodyDto,
    JustificationDiscountHeaderDto,
    JustificationDiscountGeneratorDto,
)


class JustificationDiscountReportGenerator(Generator):

    def __init__(
        self,
        repository,         # type: JustificationDiscountRepository
        initial_date,       # type: str
        end_date,           # type: str
        operator_id,        # type: str
        pos_id,             # type: str
    ):
        # type: (...) -> None

        self.repository = repository
        self.initial_date = initial_date
        self.end_date = end_date
        self.operator_id = operator_id
        self.pos_id = pos_id

    def generate_data(
        self,
    ):
        # type: (...) -> JustificationDiscountGeneratorDto

        justification_discount_report = JustificationDiscountReport(
            justification_discount_repository=self.repository,
        )

        justifications = justification_discount_report.get_justifications(
            initial_date=self.initial_date,
            end_date=self.end_date,
            operator_id=self.operator_id,
        )

        header = JustificationDiscountHeaderDto(
            operator=self.operator_id,
            start_date=self.initial_date,
            end_date=self.end_date,
            pos_id=self.pos_id,
        )

        body = JustificationDiscountBodyDto(
            justifications=justifications,
        )

        return JustificationDiscountGeneratorDto(
            header=header,
            body=body,
        )
