module IdCardPrinterService
    class SampleJasperUrlGenerator

        def initialize(employer, sample_key, sample_title)
            @sample_key = sample_key
            @sample_title = sample_title
            @card_setup = employer.id_card_setup
        end

        def call
            # @net_logo = determine_network_logo

            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
            @card_setup.network_logo.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
            {
                host: '10.41.1.115',
                port: 8080,
                path: '/trunk/IdCardsServlet',
                query: "reportConn=BrittonConnect&cardTemplate=#{@card_setup.card_template}&printType=SampleCard&sample_key=#{@sample_key}&sample_plan_title=#{@sample_title}&employer_logo=#{@card_setup.employer_logo.filename}&network_logo=#{determine_network_logo}&FileType=PDF"
            }
        end
        
    end
end