module BenefitsWordDocService
    class MapNetworkInformation

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

        def call
            # network = @word_doc_section.each do |line|
            #     if line.match?(/cigna/i)
            #         return "Cigna"
            #     elsif line.match?(/medcost/i)
            #         return "Medcost"
            #     end
            # end

            network = @word_doc_section.find do |line|
                if line.match?(/cigna/i)
                    break "Cigna"
                elsif line.match?(/medcost/i)
                    break "MedCost"
                end
            end

            # yellow_fruit_names_filtered = @word_doc_section.filter_map do |line|
            #     item[:name] if item[:color] == 'yellow'
            # end

            if network
                @card_setup.network_provider = network
                logo_name = "#{network}Logo.png"
                @card_setup.network_logo = IdCard::NetworkLogo.find_by(filename: logo_name)
                @card_setup.provider_section = IdCard::ProviderSection.find_by(title: network)
                @card_setup.rx_section = IdCard::RxSection.find_by(title: "FairosRx")
            end


            @employer
        end

    end
end