package com.agilex.healthcare.schedulingmanager.dataservice;

import java.io.OutputStream;
import java.util.Locale;

import javax.servlet.http.HttpServletRequest;

import org.springframework.context.MessageSource;

import com.agilex.healthcare.mobilehealthplatform.domain.Patient;
import com.agilex.healthcare.mobilehealthplatform.domain.PatientIdentifier;
import com.agilex.healthcare.schedulingmanager.datalayer.SMPatientDataLayer;
import com.agilex.healthcare.schedulingmanager.datalayer.pdf.PdfDataLayer;
import com.agilex.healthcare.schedulingmanager.datalayer.pdf.PdfDataLayerItext;
import com.agilex.healthcare.schedulingmanager.domain.SMConsult;
import com.agilex.healthcare.schedulingmanager.pdf.PdfGenerationContext;

public class PdfDataService {

    private PdfDataLayer pdfDataLayer;

    public PdfDataService() {
        this.pdfDataLayer = new PdfDataLayerItext();
    }

    public void generateReport(OutputStream outputStream, PdfGenerationContext context) {
        this.pdfDataLayer.generateConsultPdf(outputStream, context);
    }

    public PdfGenerationContext buildContext(
            HttpServletRequest req,
            PatientIdentifier patientIdentifier,
            MessageSource messageSource,
            SMConsult smConsult,
            SMPatientDataLayer smPatientDataLayer) {

        PdfGenerationContext context = new PdfGenerationContext();
        context.setPatientIdentifier(patientIdentifier);
        context.setMessageSource(messageSource);
        context.setLocale(Locale.US);
        context.setInformation("consult", smConsult);
        context.setProviderReport(true);
        Patient patient = smPatientDataLayer.getPatient(context.getPatientIdentifier());
        context.setPatient(patient);
        return context;
    }

}
