package com.agilex.healthcare.schedulingmanager.pdf;

import com.agilex.healthcare.schedulingmanager.domain.SMConsult;
import com.agilex.healthcare.utility.DateHelper;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;

public class ConsultPage extends AbstractPage {

    private static final org.apache.commons.logging.Log logger = org.apache.commons.logging.LogFactory.getLog(ConsultPage.class);

    public ConsultPage(Document document, PageEvent event, PdfWriter writer, PdfGenerationContext context) {
        super(document, event, writer, context);
    }

    @Override
    public void create() {

        try {
            SMConsult smConsult = (SMConsult)context.getInformation("consult");
            PdfPTable consultInformationTable = createInformationTable();
            addInformationRow(consultInformationTable, false,context.getMessageSource().getMessage("scv.report.consults.patient", null, context.getLocale()),context.getPatient().getDisplayName());
            addInformationRow(consultInformationTable, false,context.getMessageSource().getMessage("scv.report.consults.dob", null, context.getLocale()), DateHelper.formatDate(context.getPatient().getDateOfBirth().getDate()));
            document.add(consultInformationTable);
            Paragraph note = new Paragraph(smConsult.getText(), Stylesheet.getNormal());
            setupParagraph(note);
            document.add(note);

        } catch (DocumentException e) {
            logger.error("Error generating PDF document ", e);
            throw new PDFException("Error creating PDF document " + e.getMessage());
        }
    }
    private void setupParagraph(Paragraph paragraph) {
        paragraph.setIndentationLeft(5);
        paragraph.setIndentationRight(5);
        paragraph.setLeading(0f, 1.0f);
        paragraph.setSpacingAfter(5.0f);
    }
}
