module IdCardPrinterService
    class JasperBatchUrlGenerator

        def initialize(card_template, jasper_batch_id, layout)
            @card_template = card_template
            @jasper_batch_id = jasper_batch_id
            @layout = layout
        end

        def call
            URI::HTTP.build(url_components)
        end

        private

        # def determine_network_logo
        #     # if @network_logos.length > 1
        #     #     member_geographic_info = Vhcs::PbEntityAddress.joins("INNER JOIN vwMBMember ON PBEntityAddress.PBEntityKey = vwMBMember.PBEntityKey AND PBEntityAddress.AddressTypeID = 1137").where("vwMBMember.FamilyID = ?", @family_id).first
        #     #     @network_logos.where.not(default: true).each do |pnl|
        #     #         if member_geographic_info[pnl.exception_type] == pnl.exception_value
        #     #             return pnl.net_logo
        #     #         end
        #     #     end
        #     # end
        #     # @network_logos.find_by(default: true).net_logo
        #     IdCard::NetworkLogo.find(@network_logo_id).filename
        # end
# http://localhost:8080/trunk/PdfServlet?reportConn=BrittonConnect&id=&reportName=FairosRxSampleIDCard-Half&family_id=Classic%202K&employer_logo=BryanPestControl.jpeg&network_logo=CignaLogo.png&reportDir=secure/Documents&SUBREPORT_DIR=/&ImageDir=secure/Documents&netToken=3a4a8b03f4dfb0e6e3fc82dd369f70ef&FileType=PDF
# http://localhost:8080/trunk/PdfServlet?reportConn=BrittonConnect&id=&reportName=FairosRxSampleIDCard-Half&family_id=Classic%202K&employer_logo=BryanPestControl.jpeg&network_logo=CignaLogo.png&reportDir=secure/Documents&SUBREPORT_DIR=/&ImageDir=secure/Documents&netToken=3a4a8b03f4dfb0e6e3fc82dd369f70ef&FileType=PDF
        def url_components
            components = {
                host: ENV["JASPER_SERVER_HOST"],
                path: '/IdCardsServlet',
                query: "reportConn=BrittonConnect&cardTemplate=#{@card_template}&printType=#{@layout}&jasper_batch_id=#{@jasper_batch_id}&FileType=PDF"
            }
            if ENV["JASPER_SERVER_PORT"].present?
                components.merge!(port: ENV["JASPER_SERVER_PORT"])
            end
            components
        end
    end
end