import json


class DocGenServiceError(Exception):
    pass


class DocGenService(object):
    def __init__(self, request_maker, request_builder):
        self.request_maker = request_maker
        self.request_builder = request_builder

    def generate(self):
        url = 'https://dcs.us.sunpower.com/ws/docgen/docx/generatePdf'
        headers = {'content-type': 'application/json'}
        params = json.dumps(self.request_builder.build())

        result = self.request_maker.post(url, params, headers=headers)

        if result.status_code != 200:
            raise DocGenServiceError(result.content)
        return result.content
